Some initial settings for psql on Windows 10
- First, verify the installation is complete (postgres is the default admin user).
psql -U postgres
- You can use
\q
to exit, use\l
to show all databases, use\dt
to show all tables under the current database. - Create a user with the same username as your login name (your account name for Windows). Here, we need to execute this command with the default admin user
posrgres
(because we do not have any other user at this time). The name for the new user should be the same as your Windows login name (for my example, it’sjohn
). We should specify the-P
parameter because we need the new user to have a password. We also use the--interactive
option to make this process easier.createuser -U postgres -P --interactive john
- Now, we can user the new user created just now to log into the database system. However, PostgreSQL requires all users to have a database with the same name as their username. Since there is no database for
john
now, let’s just usepostgres
.psql -d postgres
- Finally, create a database called
john
. Use\l
to check the result.CREATE DATABASE john;
- From now on, you can simply use
psql
in a terminal to use PostgreSQL CLI.
Troubleshooting
- Postgres complains that
XXX command is not found
. Make sure you have added the correct directories into yourPATH
. - Postgres complains something else. Check your permission or see PostgreSQL documentation.