Connecting to PostgreSQL on Raspberry via psql

In the previous post we’ve already explained how to set the Raspberry PostgreSQL server to allow incoming connections.

PostgreSQL shell client isĀ psql. Unlike pgAdminIII, psql is the terminal-based front-end to PostgreSQL, included in by default in the PostgreSQL package. psql enables to type in queries interactively, and provides meta-commands and shell-like features to facilitate writing scripts and automating a wide variety of tasks.

From a remote machine, follow those steps:

  • Create the ~/.pgpass file, and insert the following line:


    where hostname is the host name/IP address of the Raspberry PI, port is the number of the port where PostgreSQL is listening, database is the name of the database to connect, and username and password are the user credentials to use to connect to the database.
  • launch the following command to connect to PostgreSQL:

    psql -d database -U user -h hostname -p port

    if port is not specified, the default value (5432) is used by default.

Is possible to use a file as source of SQL statements (scriptfile.sql) through the -f option:

psql -d database -U user -h hostname -p port -f scriptfile.sql

One thought on “Connecting to PostgreSQL on Raspberry via psql

  1. Pingback: Connecting to PostgreSQL on Raspberry via Python | Raspberry PG

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>