2016-09-22 12:43:57 +00:00
---
title: About the postgres_conf Resource
---
# postgres_conf
Use the `postgres_conf` InSpec audit resource to test the contents of the configuration file for PostgreSQL, typically located at `/etc/postgresql/<version>/main/postgresql.conf` or `/var/lib/postgres/data/postgresql.conf`, depending on the platform.
2017-10-03 21:35:10 +00:00
<br>
2016-09-27 19:03:23 +00:00
## Syntax
2016-09-22 12:43:57 +00:00
A `postgres_conf` resource block declares one (or more) settings in the `postgresql.conf` file, and then compares the setting in the configuration file to the value stated in the test:
describe postgres_conf('path') do
its('setting') { should eq 'value' }
end
2017-06-23 15:31:27 +00:00
2016-09-22 12:43:57 +00:00
where
* `'setting'` specifies a setting in the `postgresql.conf` file
* `('path')` is the non-default path to the `postgresql.conf` file (optional)
* `should eq 'value'` is the value that is expected
2017-10-03 21:35:10 +00:00
<br>
2016-09-22 12:43:57 +00:00
2016-09-27 19:03:23 +00:00
## Examples
2016-09-22 12:43:57 +00:00
The following examples show how to use this InSpec audit resource.
2016-09-27 19:03:23 +00:00
### Test the maximum number of allowed client connections
2016-09-22 12:43:57 +00:00
describe postgres_conf do
its('max_connections') { should eq '5' }
end
2016-09-27 19:03:23 +00:00
### Test system logging
2016-09-22 12:43:57 +00:00
describe postgres_conf do
its('logging_collector') { should eq 'on' }
its('log_connections') { should eq 'on' }
its('log_disconnections') { should eq 'on' }
its('log_duration') { should eq 'on' }
its('log_hostname') { should eq 'on' }
its('log_line_prefix') { should eq '%t %u %d %h' }
2017-06-23 15:31:27 +00:00
its(['pgaudit.log_parameter']) { should cmp 'on' }
2016-09-22 12:43:57 +00:00
end
2016-09-27 19:03:23 +00:00
### Test the port on which PostgreSQL listens
2016-09-22 12:43:57 +00:00
describe postgres_conf do
its('port') { should eq '5432' }
end
2016-09-27 19:03:23 +00:00
### Test the Unix socket settings
2016-09-22 12:43:57 +00:00
describe postgres_conf do
its('unix_socket_directories') { should eq '.s.PGSQL.5432' }
its('unix_socket_group') { should eq nil }
its('unix_socket_permissions') { should eq '0770' }
end
where `unix_socket_group` is set to the PostgreSQL default setting (the group to which the server user belongs).
2017-10-03 21:35:10 +00:00
<br>
## Matchers
2018-01-31 12:24:16 +00:00
For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
2017-10-03 21:35:10 +00:00
### setting
The `setting` matcher tests specific, named settings in the `postgresql.conf` file:
its('setting') { should eq 'value' }
Use a `setting` matcher for each setting to be tested.