I don't understand how Postgres works with openBSD. I didn't have these problems with debian (I don't have to do the initdb).
I did as follow
pkg_add postgresql-server php-pgsql
su - _postgresql
initdb -D /var/postgresql/data -U postgres - E UTF8 -A md5 -W
But after that, I don't have the result that I expect
I can start the database with
pg_ctl -D /var/postgresql/data/ -l logfile start
or with
rcctl enable postgresql
rcctl start postgresql
But I don't understand how to connect to it
Because if I do:
# su - _postgresql
$ psql
Password:
psql: FATAL: password authentication failed for user "_postgresql"
Why it's the _postgresql user and not postgres?
Which password I'm supposed to use?
This is the pg_hba.conf, I changed the end,
# 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
password
# IPv6 local connections:
host all all ::1/128 md5
So with this, I think, i'm login but I have a new probleme, there is really something I don't understand
$ pg_ctl -D /var/postgresql/data/ -l logfile stop
waiting for server to shut down.... done
server stopped
$ pg_ctl -D /var/postgresql/data/ -l logfile start
server starting
$ psql
psql: FATAL: role "_postgresql" does not exist
thanks
So the normal case when a create a new database is
With the user
su - _postgresql
initdb -D /var/postgresql/data -U postgres -k -E UTF8 -A md5 -W
and you have to chose a password
Start the database
pg_ctl -D /var/postgresql/data/ -l logfile start
And you can easily login with
psql -U postgres
But if it didn't work, i suppose i did a mistake with the password
With the user
su - _postgresql
First I need to change the ph_hba.conf to trust
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
so when I start the database with
pg_ctl -D /var/postgresql/data/ -l logfile start
so I can login with the postgres user
psql -U postgres
And finaly change the password
ALTER USER postgres WITH PASSWORD '123';
Don't forget the " ; " at the end!
Change the pg_hba.conf file
First I need to change the ph_hba.conf to password (or maybe MD5)
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all password
And restart
pg_ctl -D /var/postgresql/data/ -l logfile stop
pg_ctl -D /var/postgresql/data/ -l logfile start
And i can finaly login properly
psql -U postgres
Related
I have started a PostgreSQL process as follows:
pg_ctl start -w -D /path/to/data -l /path/to/log -o "-F -k /path/to/unix/socket -h ''"
(alternatively -h '*' instead of -h '')
Aside, references for pg_ctl (the outer function) and postgres (the -o parameter)
and created a user (with password) and database:
createuser -P admin
createdb -O admin db
I can connect to the database via the unix socket (does not trigger a password prompt):
psql -h /path/to/unix/socket -U admin -d dbname
but connecting via the TCP port fails:
psql -h localhost -U admin -d dbname
Password for user snaprevs_admin:
psql: FATAL: password authentication failed for user "admin"
What do I need to change so that both the unix socket and TCP connections work as expected?
If you are performing a custom pg_ctl launch, you should check that there isn't a default service already running. If there is it will consume the default TCP port.
To stop the default service and prevent it from starting on next boot:
sudo systemctl disable postgresql --now
If you only want to stop it temporarily:
sudo service postgresql stop
You should now be able to stop and re-start your custom service (with -h '*'), then log in over TCP.
sup guys!
I'm trying to create a server local in pdAdmin 4, but everytime i'm trying to create i get this error:
[Error in pgAdmin]
in case 'veterano' its my username...
my tries to make this run (but doesnt work)
Checking if Postgres Service is Installed correctly:
$ sudo systemctl is-active postgresql
terminal back:
active
$ sudo systemctl is-enabled postgresql
terminal back:
enabled
$ sudo systemctl status postgresql
terminal back:
active (exited)
$ sudo pg_isready
terminal back:
/var/run/postgresql:5433 - accepting connections
My configuration to pg_hba.conf :
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# 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.
local replication all peer
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5
(every time after change something in pg_hba.conf I run $ sudo systemctl restart postgresql to restart postgress service.)
Checking psql and the new superusers:
$ sudo -u postgres createuser -s $USER
terminal back
createuser: error: creation of new role failed: ERROR: role "veterano" already exists
if I try
psql -U veterano i can login... so i try \du to check list of roles
terminal back
List of roles
Role name | Attributes | Member of
-------------+------------------------------------------------------------+-----------
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
veterano | Superuser, Create role, Create DB | {}
So I try create a localhost server in terminal:
$ psql -h localhost -d mydatabase -U veterano -p 5432
terminal back:
Password for user veterano:
(I put my password maked with ALTER USER veterano PASSWORD 'newPassword';)
terminal back error
psql: error: FATAL: password authentication failed for user "veterano"
I really don't know what to do... I tried everything and still cant create a local server in pgAdmin 4 or directly in terminal.
Using Ubuntu 20.04.2 LTS
(Sorry for my english )
This is probably too late. but I have the same issue with veterano, and what I did was to change the password for the account "postgres" that I have :
(For those who don't know, postgresql has a user named "postgres" by default after installation)
Steps:
Access PSQL
$ sudo su - postgres
Then try to change the password for "postgres" user by typing :
postgres=# \password
You can then specify any password you want for this account.
Once thats done, you can use pgAdmin to connect using "postgres" username and the password that you just set.
Either you didn't set a password for the user, or you set a different password.
Connect using psql with psql -U veterano and set the password:
veterano=> \password
Enter new password:
Enter it again:
Now you should be good.
Try putting quotation marks '' on your password at your config file.
First we have to get inside postgres through using
sudo -u postgres psql postgres
Enter password for user postgres
Now the terminal will be like this:
postgres=#
Now enter the given line after postgres=#
CREATE USER username WITH PASSWORD 'your password';
(put your password inside quotes('') and don't forget semicolon(;)
We have a postgres database server(10.3) installed on Centos7, and created a database with the name of "db_name". We have database access. The setting in pg_hba.conf is as the following:
# "local" is for Unix domain socket connections only
local all all trust
host all all 127.0.0.1/32 trust
host all all ::1/128 trust
local replication all peer
host replication all 127.0.0.1/32 ident
host replication all ::1/128 ident
When I have sudo access, I can access the database "db_name".
[root#localhost bin]# sudo -s
[root#localhost bin]# psql -U db_name db_user
psql (10.3)
Type "help" for help.
db_name=>
When I tried to access database as a regular linux user, I got the following error:
[linuxuser#localhost bin]# psql -U db_name db_user
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
The reason we want to limit some users sudo access is that our report specialists need an access to the database "db_name", but we don't want them to have the sudo privilege to do something else.
What kind of settings shall I do in order to make it work?
Thanks!
I found the solution.
The cause of the problem is that there is no /var/run/postgresql/.s.PGSQL.5432 file existed.
By default, unix_socket_directories is '/tmp' which is set in postgresql.conf.
For some reason, the regular linux user is not looking at /tmp/.s.PGSQL.5432, but instead looking at /var/run/postgresql/.s.PGSQL.5432 file.
So the fix is as the following:
cd /var/run
mkdir postgresql
cd postgresql/
ln -s /tmp/.s.PGSQL.5432 .s.PGSQL.5432
The following command works as well.
psql -h /tmp -U db_user db_name
In PostgreSQL you should create a role to access the DB.
For that you will have to do this:
Change to postgres account (Created during installation of postgresql)
$ sudo -i -u postgres
Create a new role
postgres#server createuser --interactive
Output
Enter name of role to add: DB_Name
Shall the new role be a superuser? (y/n) y
Create Database
postgres#server createdb DB_Name
Create user, change to user and access to database
$ sudo adduser DB_Name
$ sudo -i -u DB_Name
$ psql
DB_Name=# \conninfo
References:
How To Install and Use PostgreSQL on CentOS 7
In Ubuntu 16.04 I created second postgres database cluster, called cmg, with a local user as the admin user:
pg_create -u "local_username" -g "local_usergroup" -d /path/to/data/dir 9.5 cmg
The cluster was started with:
pg_ctrlcluster 9.5 cmg start
which ran successfully (pg_lsclusters show both are online)
The problem is I cannot connect to the cluster using psql as is normally done.
I tried using:
psql -h 127.0.0.1 -w -p5433 -U local_username
which fails with:
psql: fe_sendauth: no password supplied"
Is there any way to connect to the specific cluster?
use psql -h your_socket_dir -p5433 -U postgres to connect locally (uses peer auth by default - thus high chahce to login wothout password)
once logged in - set up password (create user if needed) and use it connecting remotely
psql -h 127.0.0.1 -p5433 -U local_username
in your connect string you had -w which is never ask for a password https://www.postgresql.org/docs/current/static/app-psql.html which would by default work only for local connections
I think the default pg_hba.conf when you start up a new cluster expects you to authenticate with peer connections, so you need to change user to your local user before connecting
[root#server~]# su - local_username
>> Enter password:
> password
[local_username#server~]# psql -h 127.0.0.1 -p 5433
You can check your pg_hba.conf file in /path/to/data/dir/pg_hba.conf to see how it expects you to authenticate.
Alternatively, if you cannot get access as your 'local_username' then instead su to postgres user in the instructions above and it should work
While trying to connect to postgres running locally on my workstation, I get:
$ sudo -u postgres psql -c "create role ..."
could not change directory to "/home/esauer/workspace/cfme"
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
My postgres-server install creates sockets in /var/run/postgresql.
How do I get the client to look in the proper location?
Check the --host option with psql --help.
Then you can make it permanent by setting it in your .psqlrc user file.
In your case try:
psql -h /var/run/postgresql -d your_database