Deploy PostgreSQL with Extensions
PostgreSQL with SSL and dynamic extensions.
Postgres
Just deployed
/var/lib/postgresql
Deploy and Host PostgreSQL with Extensions on Railway
A highly customizable PostgreSQL database template equipped with native SSL support. It allows developers to dynamically install Debian APT packages and configure custom PostgreSQL extensions (like PostGIS, pgvector, or TimescaleDB) during deployment, providing a fully tailored and secure database environment for any application.
About Hosting PostgreSQL with Extensions
Hosting this template on Railway means you don't have to worry about writing custom Dockerfiles or managing complex build processes just to get a specific extension working. By providing the desired PG_APT_PACKAGES and PG_DB_EXTENSIONS environment variables during deployment, the template automatically compiles the correct image, installs all dependencies, and runs the necessary CREATE EXTENSION SQL commands upon initialization.
Furthermore, the template generates TLS/SSL certificates internally on startup. This ensures that all connections to the database over the public internet are fully encrypted and secure by default, overcoming common limitations of standard unencrypted database templates.
Common Use Cases
- Geospatial Applications: Use the
postgisextension to handle complex location-based data and routing. - AI and Machine Learning: Implement vector similarity search for AI applications using the
pgvectorextension. - Time-Series Analytics: Process and analyze high-volume IoT or financial data using
timescaledb. - Database Automation: Schedule tasks and run periodic maintenance jobs directly inside the database using
pg_cron.
Dependencies for PostgreSQL with Extensions Hosting
- A persistent volume (automatically provisioned by Railway)
- Environment Variables configuration (for specifying versions and extensions)
Deployment Dependencies
Implementation Details
To customize your deployment, configure the following Build Arguments and Environment Variables:
Core Build Configuration:
POSTGRES_VERSION: Specifies the base PostgreSQL version to use when building the image (e.g.,18.4). Ensure the major version matches the template you deploy (18+ vs 17-).
APT & Extensions (Build-time Arguments):
PG_APT_PACKAGES: A comma-separated list of APT package names to install (e.g.,postgresql-18-postgis-3,timescaledb-2-postgresql-18).PG_EXTENSION_REPOS: A comma-separated list of APT repository URLs to add (useful for 3rd-party extensions).PG_EXTENSION_REPO_KEYS: A comma-separated list of GPG key URLs corresponding to the custom repos.
Database & Security (Run-time Variables):
PG_DB_EXTENSIONS: A comma-separated list of extension names to enable in the database (e.g.,postgis,timescaledb).PG_SHARED_PRELOAD_LIBRARIES: A comma-separated list of shared libraries to preload on server start (e.g.,timescaledb,pg_cron).SSL_CERT_DAYS: Number of days the auto-generated SSL certificate remains valid (default is820).POSTGRES_USER,POSTGRES_PASSWORD,POSTGRES_DB: Standard PostgreSQL credentials and default database name.
Security Note: To connect securely to your database, simply append ?sslmode=require (or ?sslmode=verify-full if downloading the generated root certificate) to your database connection string.
Why Deploy PostgreSQL with Extensions on Railway?
Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.
By deploying PostgreSQL with Extensions on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.
Template Content
Postgres
ncontiero/postgres-ssl