-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
PostgreSQL
PostgreSQL is a powerful, open source object-relational database system with over 30 years of active development. This package includes PostGIS spatial database extension for DSM 7+.
- Install the PostgreSQL package from SynoCommunity repository
- During installation, create an administrator account with username and password
- The default port is 5433 (to avoid conflict with Synology's built-in PostgreSQL on 5432)
Important: You must use the full path /usr/local/bin/ to run these commands, otherwise DSM's built-in PostgreSQL (on port 5432) will be used instead.
/usr/local/bin/psql -h localhost -p 5433 -U pgadmin -d postgres/usr/local/bin/psql -h /var/packages/postgresql/var -p 5433 -U pgadmin -d postgres| Command | Description |
|---|---|
psql |
PostgreSQL interactive terminal |
pg_dump |
Dump a database to a file |
pg_dumpall |
Dump all databases to a file |
pg_restore |
Restore a database from a dump file |
createdb |
Create a new database |
dropdb |
Remove a database |
createuser |
Create a new user role |
dropuser |
Remove a user role |
pg_isready |
Check if server is running |
vacuumdb |
Vacuum a database (reclaim storage) |
reindexdb |
Reindex a database |
clusterdb |
Cluster a database |
/usr/local/bin/createuser -h localhost -p 5433 -U pgadmin -P newusernameThe -P flag will prompt you to set a password for the new user.
/usr/local/bin/createuser -h localhost -p 5433 -U pgadmin -Ps newusername/usr/local/bin/dropuser -h localhost -p 5433 -U pgadmin username/usr/local/bin/psql -h localhost -p 5433 -U pgadmin -d postgresThen in psql:
-- Create a new user
CREATE USER newuser WITH PASSWORD 'password';
-- Create a superuser
CREATE USER newadmin WITH PASSWORD 'password' SUPERUSER;
-- Drop a user
DROP USER username;/usr/local/bin/createdb -h localhost -p 5433 -U pgadmin mydatabase/usr/local/bin/dropdb -h localhost -p 5433 -U pgadmin mydatabase/usr/local/bin/psql -h localhost -p 5433 -U pgadmin -d postgresThen in psql:
-- Create a database
CREATE DATABASE mydatabase;
-- Create a database owned by a specific user
CREATE DATABASE mydatabase OWNER newuser;
-- Drop a database
DROP DATABASE mydatabase;You can set up DSM scheduled tasks to run maintenance commands. Create a scheduled task with the following:
/usr/local/bin/vacuumdb -h localhost -p 5433 -U pgadmin -d mydatabase/usr/local/bin/reindexdb -h localhost -p 5433 -U pgadmin -d mydatabase/usr/local/bin/pg_dump -h localhost -p 5433 -U pgadmin -Fc mydatabase -f /volume1/backup/mydatabase.dumpIf you're running on DSM 7+ (GCC 5+), PostGIS is automatically enabled for all new databases. To enable PostGIS manually:
CREATE EXTENSION IF NOT EXISTS postgis;- Default authentication is scram-sha-256 (stronger than md5)
- The wizard enforces password complexity requirements
- Local connections use peer authentication (socket must be owned by PostgreSQL user)
Ensure you're using port 5433 (not the default 5432):
/usr/local/bin/psql -h localhost -p 5433 -U pgadmin -d postgres/usr/local/bin/pg_isready -h localhost -p 5433Log file is available at /var/packages/postgresql/var/postgresql.log
- Home
-
Packages
- Adminer
- Aria2
- Beets
- BicBucStriim
- Borgmatic
- cloudflared
- Comskip
- Debian Chroot
- Deluge
- Duplicity
- dnscrypt-proxy
- FFmpeg
- FFsync
- Flexget
- Gstreamer
- Google Authenticator
- Home Assistant Core
- Jellyfin
- Kiwix
- [matrix] Synapse homeserver
- MinIO
- Mono
- Mosh
- Mosquitto
- Node-Exporter
- OpenList
- ownCloud
- PostgreSQL
- Radarr/Sonarr/Lidarr/Jackett
- rclone
- ruTorrent (rTorrent)
- SaltStack
- SickBeard Custom
- SynoCLI-Disk
- SynoCLI-Devel
- SynoCLI-File
- SynoCLI-Kernel
- SynoCLI-Misc.
- SynoCLI-Monitor
- SynoCLI-NET
- Synogear
- Vaultwarden
- Concepts
- Development
- Resources