Getting Started with PostgreSQL
PostgreSQL is an open-source relational database. It can store and retrieve different types of data. This guide uses PG as an abbreviation for PostgreSQL.
Use this guide if you know basic Linux commands and want to start with PostgreSQL in Pigsty. The examples use the default single-node installation. For production clusters with multiple nodes, see Service Access.
Basics
The default single-node template creates the pg-meta cluster on the current node.
This cluster has one primary instance.
PostgreSQL listens on port 5432.
The template also creates the meta database.
After installation, close your administration account SSH session.
Log in again to load the new environment variables.
Enter pp to open psql:
The command uses p as a shortcut for the pig command-line tool.
You can also use the postgres operating system account to run psql.
This connects to the default postgres administration database.
Connecting to Database
Use a command-line tool or a graphical client to connect. Supply a PostgreSQL connection string in this format:
Some drivers and clients require separate connection parameters:
| Parameter | Description | Example Value | Notes |
|---|---|---|---|
host | Database server address | 10.10.10.10 | Replace with your node IP or domain; can omit for localhost |
port | Port number | 5432 | PG default port, can be omitted |
username | Username | dbuser_dba | Pigsty default database admin |
password | Password | DBUser.DBA | Pigsty default admin password (change this!) |
dbname | Database name | meta | Default template database name |
For personal administration, you can use dbuser_dba.
This account is a database superuser with full privileges.
If you ran configure -g, the script generated a random administration password.
Find the password in ~/pigsty/pigsty.yml:
Default Accounts
The default single-node template defines these database accounts:
| Username | Password | Role | Purpose |
|---|---|---|---|
dbuser_dba | DBUser.DBA | Superuser | Database admin (change this!) |
dbuser_meta | DBUser.Meta | Business admin | App R/W (change this!) |
dbuser_view | DBUser.Viewer | Read-only user | Data viewing (change this!) |
These examples connect to the same meta database with different accounts:
Replace the example IP address and password with your actual values.
The configure -g command replaces the three example passwords with random passwords.
See Security Recommendations for its complete scope and limitations.
Using CLI Tools
psql is the PostgreSQL command-line client.
On a Pigsty node, use one of these methods to connect to the local database:
Replace the example IP address and password before you run the connection commands.
After a successful connection, psql shows a prompt:
Common psql commands
Enter SQL statements at the prompt.
To run a psql meta-command, start the command with \.
| Command | Description | Command | Description |
|---|---|---|---|
Ctrl+C | Interrupt query | Ctrl+D | Exit psql |
\? | Show all meta commands | \h | Show SQL command help |
\l | List all databases | \c dbname | Switch to database |
\d table | View table structure | \d+ table | View table details |
\du | List all users/roles | \dx | List installed extensions |
\dn | List all schemas | \dt | List all tables |
SQL example
End each SQL statement with a semicolon (;).
This example creates a test table, adds two rows, queries the rows, and removes the table:
Using Graphical Clients
You can also connect with a graphical client.
Grafana
The INFRA module includes Grafana and a PostgreSQL data source named Meta. Open the Web UI. Use the Grafana Explore panel to query PostgreSQL with SQL. This method requires no additional client software.
The default Grafana username is admin.
Find its password in grafana_admin_password in the inventory.
The default password is pigsty.
DataGrip
DataGrip is a database development tool from JetBrains. IntelliJ IDEA also has a Database Console that can connect to PostgreSQL.
DBeaver
DBeaver is a free, open-source database client. It runs on multiple desktop operating systems and supports PostgreSQL and other databases.
pgAdmin
pgAdmin is a PostgreSQL administration client from PGDG. You can use its browser interface or desktop application. Pigsty supplies a pgAdmin template for deployment with Docker.
Viewing Monitoring Dashboards
Pigsty supplies PostgreSQL monitoring dashboards. They show information from cluster summaries to individual tables.
Open PGSQL Overview first. Select a cluster to see its instances and databases. Use the dashboard links to examine tables, indexes, and functions.
Trying Extensions
PostgreSQL extensions add data types, functions, index methods, and other database features. Pigsty packages 600 extensions in 16 categories. These categories include time-series data, geographic data, vectors, and full-text search.
Start with these extensions:
postgisprocesses geographic and location data. The default template installs it.pgvectorsupplies vector similarity search for AI embeddings. The default template installs it.timescaledbstores and queries time-series data. Install it when required.
Use these commands to list and enable extensions:
Next Steps
Change the configuration to define your databases, users, and extensions.
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)