User

Connecting to PostgreSQL

How to connect your application or tools to a PostgreSQL database on Opterius Panel.

Last updated 1775606400
  • Storing Passwords Securely
  • Connecting from the Terminal
  • Remote Access
  • Next Steps
  • Connection Details

    Find your connection details on the PostgreSQL database page:

    Setting Value
    Host 127.0.0.1
    Port 5432
    Database Your database name (e.g. myuser_mydb)
    User Your pg username (e.g. myuser_mydb_u)
    Password Set at creation time

    Connection Strings

    PostgreSQL URI

    postgresql://USERNAME:PASSWORD@127.0.0.1:5432/DBNAME
    

    Node.js (pg / node-postgres)

    const { Pool } = require('pg');
    
    const pool = new Pool({
      host:     '127.0.0.1',
      port:     5432,
      database: 'myuser_mydb',
      user:     'myuser_mydb_u',
      password: process.env.DB_PASSWORD,
    });
    

    Node.js (Prisma)

    In .env:

    DATABASE_URL="postgresql://myuser_mydb_u:PASSWORD@127.0.0.1:5432/myuser_mydb?schema=public"
    

    Python (psycopg2 / Django)

    # Django settings.py
    DATABASES = {
        'default': {
            'ENGINE':   'django.db.backends.postgresql',
            'NAME':     'myuser_mydb',
            'USER':     'myuser_mydb_u',
            'PASSWORD': os.environ['DB_PASSWORD'],
            'HOST':     '127.0.0.1',
            'PORT':     '5432',
        }
    }
    

    Ruby on Rails

    # database.yml
    production:
      adapter:  postgresql
      host:     127.0.0.1
      port:     5432
      database: myuser_mydb
      username: myuser_mydb_u
      password: <%= ENV['DB_PASSWORD'] %>
    

    Storing Passwords Securely

    Never hardcode database passwords in your source code. Store them in environment variables:

    • For Node.js apps managed by PM2: use a .env file in your project root and load it with dotenv
    • For Laravel: the .env file in the project root
    • For any app: set environment variables before starting the process

    Connecting from the Terminal

    Via SSH or the Web Terminal:

    psql -U myuser_mydb_u -d myuser_mydb -h 127.0.0.1
    # Enter password when prompted
    

    Remote Access

    PostgreSQL is bound to 127.0.0.1 by default — remote connections are not allowed. To connect from your local machine, use an SSH tunnel:

    ssh -L 5433:127.0.0.1:5432 your-server-user@your-server-ip
    # Then connect locally to:
    psql -U myuser_mydb_u -d myuser_mydb -h 127.0.0.1 -p 5433
    

    Next Steps