Choice log no. 1778481744 – PostgreSQL 18 Initial Configuration

Service account
Database cluster
Configuration files

Service Account – Dedicated operating system user that runs the server daemon. Always use a dedicated account. Limit access to PostgreSQL data.

  • Items managed by the server
  • Data files
  • Configuration files

Should not own the executables or binaries.

  • Prevents modification by the server process
  • Avoids malicious activity if it’s compromised

Pre-packaged installations ensure a suitable user

Database Cluster – Collection of databases managed by one server, can be one or multiple databases. Initialize database storage with initdb.

Sets the “data directory”

  • Data files
  • Default for configuration files

initidb creates default databases

  • postgres – primary default database. Good for utilites, users, and third-party applications to use, as the database is standard database that all expect to be there.
  • Template1 is what the system copies when creating new database. Anything added to this database will be available in all new databases.
  • Template0 – remains a clean default copy in case a new is needed that does not have the usual user modifications.

initdb also sets defaults, such as local, sort order, and encoding

Configuration Files – The primary method for configuring PostgreSQL is going to be configuration files. This is where a number of parameters that control the system behavior. Configuration parameters within these are not arbitrary text. The parameters do have defined data types and syntax rules. The values in these files can be overridden with SQL or the shell to provide temporary or user-specific modifications. Normally located in the “data directory” (this is configurable). There are multiple files. Some of the primary ones are postgresql.conf (primary source of configuration). There is also pg_hba.conf that contains client authentication rules and pg_indent.conf, which maps operating system users to PostgreSQL users.

Primary method to set parameters

  • Defined data types and syntax rules
  • Can be overwritten with SQL or the shell
    • Normally located in the “data directory”.
      Multiple files
      • postgresql.conf
      • pg_hba.conf
      • pg_ident.conf

      Changes typically require a reload or service restart

      Validate user:
      id postgres
      uid=110(postgres) gid=112(postgres) groups=112(postgres),110(ssl-cert)

      Switch over to the user:
      sudo -i -u postgres

      Verify the default directory that was created using initdb:
      psql -c “SHOW data_directory;”

      psql -c “SHOW data_directory;”
      data_directory
      —————————–
      /var/lib/postgresql/18/main
      (1 row)

      -TBC