- Published on
Self Hosted PostgreSQL with Authorization, Login, and Security
- Authors

- Name
- Patricia Dumontier
- X
- @polyglotmaster
if doing self hosting how to do authorization login and security
Self-Hosting PostgreSQL with Authorization, Login, and Security
When self-hosting a PostgreSQL database for your desktop and mobile apps to share invoice data for electrical motor repairs, implementing authorization, login, and security is critical to protect your data and ensure only authorized users (e.g., employees) can access or modify it. Since your apps need to read and write to the same database, you’ll need a secure setup that works across platforms. This guide outlines how to achieve this with a self-hosted PostgreSQL instance, using a backend API for simplicity and security, tailored to your small company’s needs.
Architecture Overview
- PostgreSQL Database: Self-hosted on a server (e.g., VPS or office PC).
- Backend API: A Kotlin/Ktor server to manage authentication and database access (direct database connections from apps are risky).
- Apps: Kotlin Multiplatform (KMP) desktop and mobile apps interacting with the API, not the database directly.
- Security Layers: User authentication (login), API authorization, and network/database security.
This approach avoids exposing PostgreSQL to the internet directly, which is safer and easier to manage than configuring database-level access for each app.
Step-by-Step Implementation
1. Start the PostgreSQL service
brew services start postgresql@14
2. Verify the installation by connecting to the default databas
psql postgres
3. Configure a New Connection
Open the Command Palette:
Press⌘+Shift+P(on macOS) orCtrl+Shift+P(on Windows/Linux) to bring up the Command Palette. Type"PostgreSQL: New Connection"(or a similar command as specified in the extension’s documentation) and select it.Provide Connection Details:
You will be prompted to enter your PostgreSQL connection information, which typically includes:- Host: Usually
localhostif you're running PostgreSQL locally - Port: Default is
5432 - Database: Enter your initial database (often
postgres, unless you have another default) - Username:
patriciadumontier - Password: The computer login password
- Host: Usually