PSQL Basic Use Guide

After you have installed the software and the Greenplum database has been started, you can now access the database and start running queries as you please. There are several different ways to do this, however, so the below will be a very brief guide respectively.

Note: The database used below as an example is in fact configured as part of the container, so you can run these commands exactly, or create your own sandbox to play in instead!

The most basic way is to use the ‘PSQL’ command from the PowerShell command line. Running the below as gpadmin on the container/VM will connect you to the ‘demo’ database:

psql -d demo

To exit out of the database run:

\q

You can, still using the ‘PSQL’ command, run queries directly against the database using either the ‘-c’ or‘-f’ option, which allows you to submit a query from the command line or from a file respectively:

psql -d demo -c “select ‘hello world’ as example;”

psql -d demo -f example.sql

Should you wish to do so, you may use the following command to create your own database to test in:

psql -d demo -c “create database sandbox;”

Finally, you can also connect to a Greenplum database running on the container via a compatible PSQL GUI Client of your choice.

Once you have started your client, navigate accordingly to add a new server, fill in any required details and head to the respective ‘Connection’ tab. Simply add in the details below and then connect your session:

  • Hostname - localhost

  • Port number - 5432

  • Database - demo

  • Username - gpadmin

Once submitted, your client should connect to the desired database and queries can now be run from here.

You may additionally be able to connect from a remote host by using the IP address of the hosting system.

However, this will depend on how any firewalls are configured and is not guaranteed to work.

Last updated