How to enable pg_audit on railway postgres?
Anonymous
PROOP

10 days ago

Can't seem to find a way to enable this extension, why is that?

Solved$40 Bounty

17 Replies

Railway
BOT

10 days ago

Hey there! We've found the following might help you get unblocked faster:

If you find the answer from one of these, please let us know by solving the thread!


Based on the Railway documentation, you should be able to enable the pg_audit extension on your PostgreSQL database with the extensions.

Using the Extensions Tab

Railway provides an Extensions tab for PostgreSQL that allows you to manage extensions. You can view, install, and uninstall extensions that are available in the Postgres image directly through this interface.

  1. Navigate to your PostgreSQL database in Railway

  2. Open the Extensions tab

  3. Look for pg_audit in the available extensions list

  4. Install it through the UI

If pg_audit isn't listed

For some reason my If pg_audit is not available in the Extensions tab, you might need to make your own PostgreSQL dockerfile and deploy it that way. You would need to:

1. Fork the baseline railway postgres image and add pg_audit to your custom image

2. Deploy your modified version using that custom image

For more details:

- Railway PostgreSQL documentation: https://docs.railway.com/guides/postgresql

- Database View guide: https://docs.railway.com/guides/database-view


Anonymous
PROOP

10 days ago

so then you would lose any auto update features of railway?:( sucks that they don't have this extension.


so then you would lose any auto update features of railway?:( sucks that they don't have this extension.

You can always use a different PostgreSQL database maintained by someone else. The Supbase PostgreSQL image has pg_audit included by default and seems well maintained.

If you:

  • setup a new blank service

  • set the image to supabase/postgres (see their GitHub here)

  • set the environment variables for username, password, database, host, etc

  • setup auto-updates for the service in service settings

  • create/mount a volume to the service at the data path (/var/lib/postgresql/data)

You should get a brand-new PostgreSQL database with a whole bunch of extensions enabled, including pg_audit.

The issue is that pg_audit isn't a standard PostgreSQL extension and as far as I can tell it requires custom binaries be downloaded and moved around inside of the actual postgresql folder; that's not possible (or at least not reproducible) with the baseline PostgreSQL image Railway uses.


Anonymous
PROOP

10 days ago

this looks promising... trying to set it up, but what am I supposed to set as the host?


this looks promising... trying to set it up, but what am I supposed to set as the host?

You should be good to set the host as 0.0.0.0

This will listen on all interfaces which should be fine on railway as you have to explicitly expose the service via a TCP proxy anyways.

All the standard postgresql environment variables should apply as the image is just based on the same postgresql base image railway uses by default.


Anonymous
PROOP

9 days ago

wierd error:

Attachments


Anonymous
PROOP

9 days ago

wierd

Attachments


Anonymous
PROOP

9 days ago

solved that actually but now getting:

Attachments


bytekeim
PRO

9 days ago

Hello guys,

If you want to run PostgreSQL on Railway with pg_audit enabled, the easiest and fully working setup is to use the official Supabase Postgres image, which already bundles pgaudit and dozens of other extensions.

1. Use a real Supabase tag (NOT latest)

latest does not exist for this image, so it gives manifest unknown.

Use a fixed version like:

supabase/postgres:17.6.1.044

This works on Railway (Postgres 15.x tags are also available).

2. Railway Environment Variables

Add these in Service → Variables:

POSTGRES_PASSWORD=securepass
PGDATA=/var/lib/postgresql/data/pgdata

(PGDATA avoids mount ownership problems.)

Optional:

POSTGRES_USER=postgres
POSTGRES_DB=postgres

3. Railway Volume

Add a volume with:

  • Mount Path:/var/lib/postgresql/data

This is where the image expects to store its data.

4. (Only if you get ownership errors)

Use this tiny Dockerfile and deploy it instead:

FROM supabase/postgres:17.6.1.044
USER root
RUN mkdir -p /var/lib/postgresql/data \
 && chown -R postgres:postgres /var/lib/postgresql
USER postgres

This clears all FATAL: data directory has wrong ownership issues.

5. Verify pg_audit

Connect using Railway’s connection info and run:

SELECT * FROM pg_available_extensions WHERE name = 'pgaudit';
CREATE EXTENSION IF NOT EXISTS pgaudit;
SELECT * FROM pg_extension WHERE extname = 'pgaudit';

If it shows up, your image includes pgaudit (Supabase images do).

I hope this helps you get a fully working PostgreSQL instance on Railway with pg_audit enabled, using a supported Supabase Postgres build with persistent storage and no initialization or ownership errors.


Anonymous
PROOP

9 days ago

yeah I'm running into this ownership error, I even tried the railway provided supabase template and it showed the same error. Why is that? How do I use the tiny Dockerfile to update it?


bytekeim
PRO

9 days ago

just wanted to check in on fixing that container issue:

1 Do you feel comfortable with GitHub for deploying a custom Dockerfile to Railway? (It's pretty straightforward)

2 Would a step-by-step guide for tweaking the Railway template to include the Dockerfile fix be helpful?

3 Are you looking to preserve your current database data, or would starting fresh be OK if needed to sort out those ownership problems?


Anonymous
PROOP

9 days ago

  1. yeah I could but not preferred

  2. absolutely

  3. no its fine, our real data is still on aws and thats what I wanna migrate.


yeah I could but not preferredabsolutelyno its fine, our real data is still on aws and thats what I wanna migrate.

Alright; I made a template for the Supabase/PostgreSQL image. I also ran into the ownserhip issue and found a fix for it on S.O

Will post here soon. Just validating it.


yeah I could but not preferredabsolutelyno its fine, our real data is still on aws and thats what I wanna migrate.

Arlght! Here's a fully functional template that should be a 1-click deploy of the Supabase PostgreSQL image

It even works with the Railway UI for PostgreSQL which is sweet so you can browse your tables, execute queries, and view extenions all within Railway

There was an existing template but it had a 100% deploy rate on recent deploys which tells me it wasn't working very well ha.


Anonymous
PROOP

9 days ago

You rock!!! Thanks buddy!


Anonymous
PROOP

9 days ago

DAMMIT, now this build doesn't have uuid-ossp extension:(


Status changed to Solved brody 9 days ago


Loading...