How to set password for Postgresql administration?

Asked

Viewed 10,814 times

6

I installed Postgresql on my Ubuntu using "apt-get". I’ve been using "sudo" to perform operations (actually following a tutorial), but now I want to manage DBMS with a client that asks me the administrator password "postgres".

How I define this password?

2 answers

8

To change the postgres user password, type the command:

$ sudo passwd postgres

After executing the command the following messages will appear:

Digite a nova senha UNIX: 
Redigite a nova senha UNIX: 

Enter your password and write it down next. Once done, we will log in with the postgres user.

$ su postgres

The password that will be required is the same one we just changed.

Now let’s change the password to connect to the bank.

This command is for version 7 or higher:

$ psql -c "ALTER USER postgres WITH PASSWORD 'nova_senha'" -d template1

Where nova_senha will be the password you want.

Source: vivaolinux.

  • 3

    An answer with just the link is bad practice here. If that link disappears one day, then that answer is garbage. If you improve the answer with good content I vote +1

  • Wow, I hadn’t even thought about it. I’m sorry, I’ll edit the answer. I thought it would be wrong to copy the content from another site.

  • 1

    You can copy the content if you refer from where you copied it.

  • 1

    Edited, thanks for understanding had not thought of this possibility.

  • If possible @fymoribe puts the command parts inside tags: `` to highlight the command, e.g.: $ su postgres

  • 1

    Changed @iTSangar

Show 1 more comment

6

Access the Postgres administration bank with this command:

sudo -u postgres psql postgres

Set administrator user password using:

\password postgres

After typing and confirming the password use the "Crtl+D" shortcut to finish the bank administration.

  • 1

    +1 to avoid the ALTER USER, that leaves the new explicit password on the screen, ~/.psql_history user and Postgresql log if there is a syntax error or configuration parameter log_statement is configured to ddl or all.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.