For this example, we are going to use ngrok. ngrok exposes local servers behind NATs and firewalls to the public internet over secure tunnels.
docker run --rm -p 5432:5432 -e POSTGRES_PASSWORD=secret -e POSTGRES_DB=demo postgres
For more details on configuration, see
postgres on Docker Hub.
Now that Postgres is running on port
5432, you can connect to the local database outside of the container using
psql -U postgres -h localhost -p 5432 postgres
Next, we can create a tunnel using ngrok and expose the locally running database.
ngrok tcp 5432
For more information, see ngrok tcp.
Note: You'll need to create an ngrok account to use tcp forwarding.
Now that Postgres and ngrok are running, you can connect to the publically exposed database using
psql -h 0.tcp.ngrok.io -p 17618 -U postgres -d postgres
That's it! You can now connect to your local instance over the internet.
This method super helpful to quickly test and analyze behavior using PostgreSQL with cloud services. For example, you can add the local Postgres to Meroxa:
meroxa resource add localpg --type postgres --url "postgres://postgres:email@example.com:19272/demo?sslmode=disable"
Note: Since our database is local, SSL is not enabled by default. To connect, you'll need to append
?sslmode=disable to the Postgres connection URL.
By adding it as a Meroxa Resource, you can easily capture real-time CDC events for every insert, update, delete operation from a local Postgres table. For more, see Postgres Connector Documentation.
I can't wait to see what you build 🚀.