PostgreSQL 16: Setup, Roles, and Remote Connections
Connect your application to a PostgreSQL service, get roles and schema privileges right, and take backups with pg_dump.
Sur cette page
Databases guides
Unlike MySQL, PostgreSQL keeps role privileges and database privileges separate. This is where most people get stuck: letting a role connect to a database does not mean it can create tables in it. This guide creates an application role from scratch and grants only what it needs.
First connection and the superuser#
When you create the service, the initial user and password are set through environment variables; you can see them under 'Startup Variables' on the service detail page. Make the first connection with that user, then create a separate role for your app -- running your app as superuser turns a single SQL injection bug into the loss of the whole cluster.
# Panelde yazan IP ve portu kullanin
psql "postgresql://postgres:[email protected]:5432/postgres"
# Baglanti kuruldu mu?
postgres=# SELECT version();A dedicated role and database for the app#
-- 1) Rolu olustur (LOGIN olmadan baglanamaz)
CREATE ROLE uygulama WITH LOGIN PASSWORD 'guclu-bir-parola';
-- 2) Veritabanini bu rolun sahipligiyle olustur
CREATE DATABASE uygulama_db OWNER uygulama;
-- 3) Herkese acik public semasindan yazma yetkisini al
\c uygulama_db
REVOKE CREATE ON SCHEMA public FROM PUBLIC;
-- 4) Yalnizca uygulama rolune ver
GRANT ALL ON SCHEMA public TO uygulama;Keeping remote access safe#
- Instead of exposing the port to the world, allow only your application server's IP.
- Keep the password in the service's environment variables, not in application code.
- Use different roles and passwords per environment; sharing one password means a leak in staging is a leak in production.
- For read-only consumers, create a separate role limited to SELECT.
Taking backups with pg_dump#
Backup and restore
# Ozel bicim (-Fc): sikistirilmis ve secici geri yuklemeye uygun
pg_dump -Fc \
-h 192.0.2.10 -p 5432 -U uygulama \
-d uygulama_db \
-f uygulama_db_$(date +%F).dumpDépannage
connection refused / timeout
The service is stopped, the wrong port is used, or PostgreSQL only listens on localhost.
Confirm the service is running and check the port on the 'Address' card; make sure listen_addresses is set to '*'.
permission denied for schema public
PostgreSQL 15+ behaviour: the role can connect but has no CREATE privilege on the schema.
Run GRANT ALL ON SCHEMA public TO <role>; while connected to that database.
too many clients already
The app opens a new connection per request and never closes it, filling max_connections.
Use a connection pool in the application and keep the pool size below max_connections.
Questions fréquentes
Should I migrate from MySQL to PostgreSQL?
If you already have a working MySQL setup, migrate only for a concrete reason: JSONB indexing, advanced window functions, geospatial data (PostGIS) or strict typing. The migration itself has a cost, and both engines are more than enough for a typical web app.
Why can't I create a database from the panel?
PostgreSQL runs as its own service here; you create databases with CREATE DATABASE in psql rather than through the panel. The steps in this guide follow exactly that path.
Ce guide vous a-t-il été utile ?
Les retours sont directement transmis à l'équipe qui maintient ce guide.
Vous n’avez pas trouvé de solution ?
Vous pouvez ouvrir une demande auprès de notre équipe d’assistance depuis le panneau.

