Running PSQL after first PostgreSQL install on Windows 10

First, make sure Postgresql is running.  A way to start the server is by issuing postgres -D ..\data in the <install Postgresql directory>/bin/.

There are two ways to invoke PSQL in windows commaind line.  One way is directly invoking psql.exe in <install Postgresql directory>/bin/.  Issue command psql -U postgres.  A password prompt will come up.  Enter the administrator password you set up during PostgreSQL install.

Another way is to use runpsql.bat batch file in <install Postgresql directory>/scripts/.  The user will be asked to provide server (defaults to localhost), database (defaults to postgre), port (defaults to whatever port was set up during installation), user (defaults  to postgres) and password (provide whatever was set up during installation).  If you just want to use the default value, hit enter at each prompt.

Here are some common psql commands:

  • To view help for psql commands, type \?.
  • To view help for SQL commands, type \h.
  • To view information about the current database connection, type \conninfo.
  • To list the database’s tables and their respective owners, type \dt.
  • To list all of the tables, views, and sequences in the database, type \z.
  • To exit the psql program, type \q.