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
~/.pgpassfile, and insert the following line:
hostnameis the host name/IP address of the Raspberry PI,
portis the number of the port where PostgreSQL is listening,
databaseis the name of the database to connect, and
passwordare 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
portis 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
psql -d database -U user -h hostname -p port -f scriptfile.sql