I've configured everything as i would in another distro (i'm an arch user, and i installed opensuse on a desktop machine).
As :
Django and all it requirements (psycopg)
Postgresql
Created a User for my django server
Created a Database
Granted all power for the database for my new user
Then, when starting syncdb to start working i get this message (I've changed users etc.. in this thread for user:question, password:password, database:question as it is in reality with other words):
FATAL: Ident authentication failed for user "question"
After lurking i got the idea to change my pg_hba.conf file (located at : /var/lib/pgsql/data/pg_hba.conf)
This is what I have:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 ident
# IPv6 local connections:
host all all ::1/128 ident
My django conf file contains :
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'question',
'USER': 'question',
'PASSWORD': 'password',
'HOST': '127.0.0.1',
'PORT': '',
}
}
I don't understand what i missed here, any ideas ?
Edit the /var/lib/pgsql/data/pg_hba.conf file and change the method from trust to md5. This way Postgres will ask for a password.
Also remember to reload the configuration file.
Have you tried changing:
host all all 127.0.0.1/32 ident
to:
host all all 127.0.0.1/32 md5
It appears that you are connecting via TCP (so the first line in pg_hba.confg with "trust" doesn't apply) and authenticate via ident, which requires entries in pg_ident.conf. You probably want "md5" or one of the other password-based authentication options.
Related
Note - I have never stood up a ruby app like this from the ground up and I am also very unfamiliar with Azure.
I am trying to connect to an existing DB on hosted on Azure via ActiveRecord. I am using ActiveRecord independently of Rails so any convention magic will be unavailable to me. I am currently unable to connect to the database and am unsure if my code configuration is incorrect, if I haven't configured azure correctly, or perhaps my account doesn't have the correct permissions. With my lack of experience I am just unable to determine which is which.
I am currently getting the Login Failed for user '<username>' error from tiny-tds. I've quadruple checked my username and pass and confirmed it is the same credentials I am using to log into the DB from Azure Data Studio. I have also created an app registration from which I got our client id and secret. I'm pretty sure that using the same url for host and resource is not correct but I'm not sure what resource is tbh. With all that said here is my code snippet.
require 'active_record'
ActiveRecord::Base.establish_connection(
adapter: 'sqlserver',
tenant_id: '<tenant_id>',
client_id: '<client_id>',
client_secret: '<client_secret>',
resource: '<servername>.database.windows.net',
active_directory_domain: '<domain> (got this from the primary domain field on the overview screen in azure portal',
host: '<servername>.database.windows.net',
username: '<username>',
password: '<pass>',
database: '<db name>'
)
class IndividualProfiles < ActiveRecord::Base
self.table_name = 'individual_profiles'
end
def run
puts 'Start'
puts IndividualProfiles.first
puts 'End'
end
run
For reference:
activerecord (4.2.11.3)
activerecord-sqlserver-adapter (4.2.18)
tiny_tds (2.1.5)
freetds (v1.3.16)
Not sure exactly what your issue is here (as I do not use all those additional options) however I did notice you are not passing the azure option (which could be the cause of your failure).
There is a configuration in the activerecord-sqlserver-adapter gem specifically for Azure. This is passed through to TinyTDS and without this configuration the connection will not work.
According to the TinyTDS README
TinyTDS is fully tested with the Azure platform. You must set the azure: true connection option when connecting. This is needed to specify the default database name in the login packet since Azure has no notion of USE [database]. FreeTDS must be compiled with OpenSSL too.
My working configurations look akin to:
connection_options = {
adapter: 'sqlserver',
encoding: 'utf8',
pool: 5,
host: '[server].database.windows.net',
database: [DATABASE_NAME],
port: 1433,
azure: true,
timeout: YOUR_TIMEOUT_VALUE,
username: ENV['SQL_USERNAME'],
password: ENV['SQL_PASSWORD']
}
If this does not work please add the following to your post:
Your ActiveRecord version
Your tiny_tds version
Your FreeTDS Version
For Example I have the following working right now: (among other configurations)
ActiveRecord (6.0.4)
tiny_tds (2.1.5)
FreeTDS (v1.00.27 - TDS version 7.3)
I have an issue with establishing a remote connection to MongoDB running on a VPS. I have followed instructions on editing the mongod.conf to bind my IP.
The network section looks like this:
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1,xx.xx.xxx.xxx
The latter IP is my local machine which I am trying to access MongoDB on using Compass.
I have also tried surrounding the list in [], but it does not work. I am restarting the mongo service after each change like so:
sudo systemctl restart mongod
When I try to run mongo after adding the new comma-separated IP to the bindIp I receive the following error.
MongoDB shell version v4.4.9
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect#src/mongo/shell/mongo.js:374:17
#(connect):2:6
exception: connect failed
exiting with code 1
When I edit the mongo.conf to remove the second IP, mongo works and I can use the shell.
I have also created a new user in the MongoDB admin to use as credentials in Compass which I am using to try to connect in Compass.
This is what the user looks like in the admin system.users collection.
{
"_id" : "admin.newAdmin",
"userId" : UUID("9b5c9a51-de6b-4e55-a2bc-3ae92d89993c"),
"user" : "newAdmin",
"db" : "admin",
"credentials" : { ... },
"roles" : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
},
{
"role" : "readWriteAnyDatabase",
"db" : "admin"
}
]
}
The connection string in Compass:
mongodb://username:password#<vps-ip>:27017/?authSource=admin&readPreference=primary&ssl=false
I have seen that replacing bindIp with 0.0.0.0 works, but I am not comfortable with that from a security point of view.
If anyone can help with a solution to securely and easily establishing a remote connection I would much appreciate it.
bindIp is a list of network interfaces to listen on mongodb server, not a list of client IPs.
Assuming mongodb is running on *nix system, list available interfaces in terminal:
ifconfig
or
ip -c a
depending on distributive
there is at least 1 virtual interface "lo" inet 127.0.0.1 - the local loop, and at least 1 physical interface associated with the network card - something like "eth0", "wifi0", etc. Numbers may differ, as well as number of interfaces.
Get the IP from inet property and add it to mongodb config.
Let me stress, bindIp does not limit who can connect to mongo, only what networks mongo listens on, so if there are only 2 interfaces - lo and eth0 there is no difference between listing both of them in the config, or using 0.0.0.0.
If you want to limit traffic from specific client IP - use system firewall.
I've failed to set up postgreSQL to work with my Ruby-on-Rails project for the past week. I've tried to uninstall and reinstall, postgreSQL, twice now.But when I try to launch postgreSQL I keep getting the error below:
could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (::1) and
accepting TCP/IP connections on port 5432?
could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (127.0.0.1) and
accepting TCP/IP connections on port 5432?"
I've looked at many online resources, including stackoverflow and none seem helpful.The key parts of my pg_hba.conf file looks like this:
# TYPE DATABASE USER ADDRESS METHOD
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5
And the key part of my postgresql.conf file is as follows:
listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5432 # (change requires restart)
max_connections = 100 # (change requires restart)
#superuser_reserved_connections = 3 # (change requires restart)
#unix_socket_directories = '' # comma-separated list of directories
# (change requires restart)
#unix_socket_group = '' # (change requires restart)
#unix_socket_permissions = 0777 # begin with 0 to use octal notation
Most of the suggestions, I've seen so far, were based on those two files. (For my case, they were already configured correctly). I also tried disabling the firewall and restarting postgreSQL but it didn't help. Does anyone have any suggestions for me? Thanks!
Got the same issue while settings up PostgreSQL 9.6.16 to work with Python/Django, but this is purely a database issue.
The solution lies in the error: In fact, I found this error mentioned within the official PostgreSQL documentation thus it's a common error.
And here is how I resolved this issue:
Always first start the postgres database server, use postgres or the wrapper program pg_ctl.I used the command, below, on windows 10.Remember, whatever comes after -D should be the path to where you installed PostgreSQL, to the data folder, which holds the pg_hba.conf and postgresql.conf files.
> pg_ctl start -D "C:/Program Files/PostgreSQL/9.6/data"
If that runs well, you are ready to access the database server.Open another cmd shell, and type the command below.Remember the password you entered while installing PostgreSQL?Enter that password when asked Password for user postgres:
> psql -U postgres
Once done, you can now go ahead to CREATE ROLE and CREATE DATABASE accordingly.
Oh my local test for Django I am attempting to switch my default local database from an old SQLLite database to a Postgres database to mimic my live environment hosted through heroku. To do this I have the postgres database locally and I changed all my settings.py as shown below, but Django does not recognize that the DB exists. In addition to this, if I run migrate or syncdb it still tries to recreate the old sqllite3 database. Anybody have any experience with this change from one database to another and see any similar problems?
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'postgres',
# Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': 'myusername',
'PASSWORD': 'mypassword',
'HOST': 'localhost', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '5432', # Set to empty string for default.
}
}
You are probably using a wrong settings file, or have something like local_settings.py that overrides your settings, or have duplicate DATABASES entries in your settings. Execute:
python manage.py diffsettings
Do you see the correct DATABASES settings there?
I am beginner in php as well Google-app engine. I have created a php webpage, I just need this to connect to external MySQL database to log user visit stats.
Under stats.php how can I include("config.php"); also in config.php how to connect:
<?php
// change these variables
$host=("example.com"); //host
$uname="abc";//MySQL username
$pass="Abc#123";//MySQL password
$db="stats"; //MySQL Database
//don't need to change
$con = mysql_connect($host,$uname,$pass);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($db, $con);
?>
When I run stats.php I am getting below error on appspot.com
Failed to connect to MySQL: Unable to find the socket transport "tcp" - did you forget to enable it when you configured PHP?
I have also confirmed connectivity to my server from outside host, port 3306 is also opened.
$ mysql -u webadmin –h (server ip) –p
I am not getting proper way to use fetch url, please help.
Thanks.
Unfortunately this won't work (yet). The reason is that the App Engine PHP runtime doesn't currently support sockets. Other App Engine runtimes (Python/Java/Go) support sockets, so it's a safe bet that it'll be added to PHP at some point in the future.
$host="example.com"; // should contain a valid host name or an ip address of the mysql server to which you want to connect
Nothing else needs to be changed, username and password only if required different. You have to make sure that the remote database does allow external connections for that username. Besides, you'd be better off using mysqli_* instead of old deprecated mysql_* extension for MySQL.
$link = mysqli_connect($host,$uname,$pass,$db) or die("Error " . mysqli_error($link));
And under stats.php you can simply include any code file the way you already mentioned:
<?php
include("config.php");
?>
$con = mysql_connect('your_my_sql_servername or IP Address', 'new_user_which_u_created', 'password');
if (!$con) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_select_db('sandsbtob',$con) or die ("could not open db".mysql_error());
and also firewall of the server must be set-up to enable incomming connections on port 3306
Hope this will help you