- PostgreSQL installed locally
- Access to postgres superuser password via
$Env:PGSU_PASSWORDenvironment variable
# Create the database
psql "host=localhost port=5432 dbname=postgres user=postgres password=$Env:PGSU_PASSWORD" -c "CREATE DATABASE autodj;"
# Create the application user
psql "host=localhost port=5432 dbname=postgres user=postgres password=$Env:PGSU_PASSWORD" -c "CREATE USER autodj WITH PASSWORD '{{AUTODJ_DB_PASSWORD}}';"
# Make autodj the owner of the database
psql "host=localhost port=5432 dbname=postgres user=postgres password=$Env:PGSU_PASSWORD" -c "ALTER DATABASE autodj OWNER TO autodj;"- Direct access to PostgreSQL server
- Full control over user creation and permissions
- Can use superuser privileges to grant ownership
- Environment variables accessible for password management
- Azure PostgreSQL doesn't provide superuser access
- Cannot run
ALTER DATABASE autodj OWNER TO autodj - Must use Azure-specific permission management
Instead of direct psql commands, you'd use:
# Create database (via Azure CLI)
az postgres db create --resource-group <resource-group> --server-name <server-name> --name autodj
# Create user (via Azure CLI)
az postgres server ad-admin create --resource-group <resource-group> --server-name <server-name> --display-name autodj --object-id <object-id>
# Or via Azure Portal: Server → Connection security → Azure Active Directory authentication-- Connect as the server admin user (not superuser)
-- Grant permissions instead of changing ownership
GRANT ALL PRIVILEGES ON DATABASE autodj TO autodj;
GRANT ALL PRIVILEGES ON SCHEMA public TO autodj;
GRANT CREATE ON SCHEMA public TO autodj;
GRANT USAGE ON SCHEMA public TO autodj;- Local:
postgresql+psycopg2://autodj:password@localhost:5432/autodj - Azure:
postgresql+psycopg2://autodj:password@<server-name>.postgres.database.azure.com:5432/autodj?sslmode=require
For containerized deployment:
# docker-compose.yml or Kubernetes config
environment:
- AUTODJ_DATABASE_URL=postgresql+psycopg2://autodj:${AUTODJ_DB_PASSWORD}@<azure-server>.postgres.database.azure.com:5432/autodj?sslmode=require- Create Azure PostgreSQL server (via Portal/CLI)
- Create database
autodj(via Portal/CLI) - Create application user
autodj(via Portal/CLI) - Grant permissions (via psql connection to Azure server)
- Configure firewall rules for your application's IP
- Update connection string with Azure server details
- Enable SSL (required for Azure)
Local setup gives you full control with superuser privileges, while Azure managed services require using Azure's permission model and cannot grant database ownership to non-admin users.