You can import and export a PostgreSQL database in Kinsta’s Database Hosting using a tool like TablePlus or the command line interface (CLI). For more details on using a database client with your PostgreSQL database, see our guide on connecting and managing your Kinsta database with TablePlus.

The installation of the database server and commands vary for each database type. This article is specific to PostgreSQL. For other database types, see:

Install PostgreSQL

If you do not yet have PostgreSQL installed on your local machine, you’ll need to install it to connect to your database. Depending on your operating system, you can install PostgreSQL in the following ways.

Windows

Download and install the GUI installer or binaries for the Interactive installer by EDB.

MacOS

With Homebrew, replace XX in the following command with the version of PostgreSQL you want to install:

brew install postgresql@XX

Debian-based Linux (Debian, Ubuntu, Mint, etc.)

Use the PostgreSQL APT repository and install the postgresql-client.

RedHat-based Linux (RedHat Fedora, CentOS, etc.)

Use the PostgreSQL Yum repository and install the postgresql-client.

Kinsta Database Credentials

You can find your database credentials under External connections on the database Info page.

Import a PostgreSQL Database

Use the following command to export the database, replacing EXTERNAL_HOSTNAME, USERNAME, PORT, and DATABASE_NAME with the information from your database’s External connections. Replace export.sql with the path and name of the database you want to import:

psql -h EXTERNAL_HOSTNAME -U USERNAME -p PORT -d DATABASE_NAME < export.sql

When prompted, enter the database password.

No output will be produced unless there are errors, which will be printed to the command line. To verify a successful import, you can use dt or a similar command to review the data in your database.

Export a PostgreSQL Database

Use the following command to export the database, replacing EXTERNAL_HOSTNAME, USERNAME, PORT, and DATABASE_NAME with the information from your database’s External connections. Replace export.sql with the path and file name of the database you want to export:

pg_dump -h EXTERNAL_HOSTNAME -U USERNAME -p PORT -d DATABASE_NAME > export.sql

When prompted, enter the database password.

Once the export is complete, your database file (e.g. export.sql) will be available at the path you specified in the pg_dump command. You can open a .sql file with a plain text editor (e.g. TextEdit, Notepad++, Sublime Text, etc.) or a database tool like TablePlus to review the exported data.

Related Documentation

Referenced Content