What is PostgreSQL?
PostgreSQL is a database program. A database stores information in an organised way. Each person or app that connects to it uses a user name and a password. Root is the all-powerful admin account on Linux. You need it, or the ability to use sudo, for this guide. Sudo means "run this command as the admin".
Steps
- Log in to your server with SSH. SSH is a safe way to type commands on a server from far away.
- Switch to the
postgresaccount. It is the main PostgreSQL admin user.sudo -i -u postgres - Open the PostgreSQL command tool, called psql.
Your prompt will change topsqlpostgres=#. - Run this command. Replace
myuserand the password with your own.
Keep the single quotes and the semicolon.ALTER USER myuser WITH PASSWORD 'NewStrongPassword'; - Look for the answer
ALTER ROLE. This means it worked. - Leave psql.
\q - Go back to your normal user.
exit
A shortcut
You can also type \password myuser inside psql. It asks you to type the new password twice and hides what you type. This keeps the password out of your command history.
If you forgot the admin password
You do not need the old password when you use the postgres system account as shown above. Most setups let that account in without a password. If yours does not, ask Hostvento support for help.
Choose a good password
- Use at least 12 characters.
- Mix letters, numbers and symbols.
- Do not reuse a password from another service.
Quick recap
- Log in with SSH and switch to the
postgresuser. - Open
psql. - Run
ALTER USER name WITH PASSWORD 'new'; - Update the password in your app too.