Skip to content

PostgreSQL databases

Custom PHP, Laravel and Node.js applications can use PostgreSQL instead of MySQL (MariaDB) or MySQL 8. Every other type keeps its own database: WordPress, Drupal and Joomla use MariaDB or MySQL 8, and static and AI agent applications have none.

You choose the engine once per server, in the Database step of Create a server. Custom PHP and Node.js servers also offer No database for applications that keep their data elsewhere.

  1. Click Create server and choose Custom PHP, Laravel or Node.js.
  2. In the Database step, choose PostgreSQL. The list also offers MySQL (MariaDB), which comes first, and MySQL 8.
  3. Finish creating the server. Every application you add to it uses that engine, and the Add application form doesn’t ask again.

Netkeel runs PostgreSQL 16. It isn’t part of a new server: the first application on a PostgreSQL server installs it while that application is created. After that it shows on the server’s page with the other services, where you can restart it.

Each application gets one PostgreSQL database and one user that owns it, with a strong random password. Netkeel manages both:

  • You can’t add more PostgreSQL databases or users to the application. Extra databases and users are a MySQL feature.
  • The password can’t be changed in the panel. Your application gets it automatically.

Open the application and go to Database › Databases to see the Engine, Database name, Database user, Host (socket folder), Port, Connection string and Password. On Custom PHP and Laravel applications, Open Adminer signs you in to the database in your browser. Node.js servers don’t run PHP, so they have no Adminer.

The database only accepts connections from the server itself. Applications connect through its socket folder, /var/run/postgresql, not through 127.0.0.1, which is blocked inside the application.

The app and its Git deploy builds get the connection details as environment variables:

Variable Value
DATABASE_URL A full connection string that uses the socket folder
PGHOST /var/run/postgresql
PGPORT 5432
PGDATABASE, PGUSER, PGPASSWORD The database name, user and password
PGSOCKET /var/run/postgresql/.s.PGSQL.5432

Variables you set yourself, under the application’s Environment, override them.

node-postgres (pg), Prisma, Knex, TypeORM and Kysely use DATABASE_URL as it is. postgres.js, and Drizzle with its postgres-js driver, can’t read the socket form of DATABASE_URL. Give them the socket and the PG* variables instead:

import postgres from "postgres";
const sql = postgres({
path: process.env.PGSOCKET,
database: process.env.PGDATABASE,
user: process.env.PGUSER,
password: process.env.PGPASSWORD,
});

See Node.js.

When you deploy from Git and don’t set any DB_* values (or DATABASE_URL) yourself, Netkeel adds the database to the application’s .env:

DB_CONNECTION=pgsql
DB_HOST=/var/run/postgresql
DB_PORT=5432
DB_DATABASE=...
DB_USERNAME=...
DB_PASSWORD=...

When it does, the deployment’s Log notes that database settings were added in shared/.env. See Laravel.

PHP reads the connection details with getenv(): DB_CONNECTION (pgsql), DB_HOST (/var/run/postgresql), DB_PORT, DB_DATABASE, DB_USERNAME and DB_PASSWORD, plus DATABASE_URL and the same PG* variables a Node.js app gets.

$pdo = new PDO(
"pgsql:host=" . getenv("DB_HOST") . ";dbname=" . getenv("DB_DATABASE"),
getenv("DB_USERNAME"),
getenv("DB_PASSWORD")
);

They are there for PHP running on the website only, not in the SSH shell or in cron jobs. See PHP and static sites.

PostgreSQL databases are part of the application’s backups, like MySQL ones. A full restore, or a database-only restore, puts the database back as it was. The application is paused while the database is replaced.

A backup’s database restores only into an application that uses the same engine. Extensions that only a PostgreSQL superuser can create can’t be restored.

On a Laravel application with migrations on, the copy taken before each deployment’s migrations works the same way. See Restore the database.