Score:0

Why it asks me to input password here to restart db

mg flag

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

user15397083 avatar
mg flag
I dont think so, it says '[sudo] password for postgres:'
Romeo Ninov avatar
in flag
Services are managed by `root` user, so use `sudo su - ` and then restart
Nikita Kipriyanov avatar
za flag
Then true, you've run the second command from the shell given to you by the first one. This is wrong, don't do it.
Score:1
za flag

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.

user15397083 avatar
mg flag
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...
Nikita Kipriyanov avatar
za flag
Run `psql -U postgres` from that postgres-user shell.
user15397083 avatar
mg flag
Thanks it was the problem of the ownership of the directory
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.