PostgreSQLConf - file /var/lib/pgsql/data/postgresql.conf

The PostgreSQL configuration file is in a fairly standard ‘key = value’ format, with the equals sign being optional. A hash mark (#) marks the rest of the line as a comment.

The configuration then appears as a dictionary in the data property.

This parser does not attempt to know the default value of any property; it only shows what’s defined in the configuration file as given.

This parser also provides several utility functions to make sense of values specific to PostgreSQL. These are:

  • as_duration(property)

    Convert the value (given in milliseconds, seconds, minutes, hours or days) to seconds (as a floating point value).

  • as_boolean(property)

    If the value is ‘on’, ‘true’, ‘yes’, or ‘1’, return True. If the value is ‘off’, ‘false’, ‘no’ or ‘0’, return False. Unique prefixes of these are acceptable and case is ignored.

  • as_memory_bytes(property)

    Convert a number given in KB, MB or GB into bytes, where 1 kilobyte is 1024 bytes.

All three type conversion functions will raise a ValueError if the value doesn’t match the spec or cannot be converted to the correct type.


>>> pgsql = shared[PostgreSQLConf]
>>> 'port' in pgsql
>>> pgsql['port']
class insights.parsers.postgresql_conf.PostgreSQLConf(context)[source]

Bases: insights.core.LegacyItemAccess, insights.core.Parser

Parses postgresql.conf and converts it into a dictionary of properties.

as_boolean(item, default=None)[source]

See :-

“Boolean values can be written as on, off, true, false, yes, no, 1, 0 (all case-insensitive) or any unambiguous prefix of these.”

as_duration(item, default=None)[source]

Postgres’s time durations for checkpoint_timeout can have ‘ms’, ‘s’, ‘min’, ‘h’, or ‘d’ suffixes. We convert all of them here to seconds.

See :-

“Valid time units are ms (milliseconds), s (seconds), min (minutes), h (hours), and d (days)”

We return a floating point number because of the possibility of convertion from milliseconds, and because maybe someone will say 8.4h.

as_memory_bytes(item, default=None)[source]

See :-

“Valid memory units are kB (kilobytes), MB (megabytes), and GB (gigabytes). Note that the multiplier for memory units is 1024, not 1000.”


Parsing rules from :

One parameter is specified per line. The equal sign between name and value is optional. Whitespace is insignificant and blank lines are ignored. Hash marks (#) designate the remainder of the line as a comment. Parameter values that are not simple identifiers or numbers must be single-quoted. To embed a single quote in a parameter value, write either two quotes (preferred) or backslash-quote.