Setting Up PostgreSQL¶
Installation¶
First download PostgreSQL on your operating system.
Secure Database Configuration¶
To ensure your database configuration is secure, do not allow access from all internet sources. Avoid settings such as 0.0.0.0/0 in pg_hba.conf and listen_addresses='*' in postgresql.conf.
For remote connections, use an SSH tunnel.
Example:
Creating Database and User¶
Create a new database and user by executing the following commands:
Secure Schema Usage¶
To enhance security, constrain ordinary users to user-private schemas. Ensure that no schemas have public CREATE privileges. For each user who needs to create non-temporary objects, create a schema with the same name as the user.
Example:
This setup ensures that users access their own schemas by default.
PostgreSQL 14 or earlier
For PostgreSQL 14, earlier versions or upgraded databases to PostgreSQL 15 and later, remove the public CREATE privilege from the public schema:
Documentation: