0

I just have done

pg_basebackup -h primary_host -p primary_port -D PGDATA -U replication user

and I jsut wanted to restart the db, so I did

sudo su - postgres

sudo service postgres restart

and the ec2 says to me

Respect the privacy of others, think before you type, ...

and it asks me password for postgres. But since I have created this ec2 instance, I have never set any password for postgres. So there is no password for this actually, but it keeps asking me...

I guess there might be something related to pg_basebackup, but I have no idea, because the primary db also has no specific password..

What should I do here, thanks

1 Answers1

1

When you run

sudo su - postgres

It invokes a new shell, which is owned by postgres user.

Then, from that shell you run another sudo:

sudo service postgres restart

And it, unsurprisingly, asks password for the current system user, which is postgres, because you ran it from the shell that belongs to postgress. Again, this is not because you set or did not set password for postgres, and this is not about database user postgres, but the OS account, whose shell was invoked with the first command.

Just skip the first command, or exit that shell when you've finished doing things as postgres system account. You should manage services with sudo from your normal admin user, not from postgres user.

Nikita Kipriyanov
  • 10,947
  • 2
  • 24
  • 45
  • thanks for your reply. But may I ask one more question here? so, inside the su - postgres bash, when I type 'psql --version', then it prints the version. but when I type 'psql -U root' or just 'psql', then it says 'psql: could not connect to server: No such file or directory'... when I type 'sudo pg_ctl -D /var/lib/pgsql/data start', it says 'pg_ctl: could not open PID file: permission denied' anyway I need to connect to the pgsql prompt... – user15397083 Mar 06 '23 at 08:37
  • Run `psql -U postgres` from that postgres-user shell. – Nikita Kipriyanov Mar 06 '23 at 08:38
  • Thanks it was the problem of the ownership of the directory – user15397083 Mar 06 '23 at 08:58