├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── analysis_options.yaml ├── example └── example.dart ├── lib ├── containers │ ├── cockroachdb.dart │ └── postgres.dart └── docker_process.dart ├── pubspec.yaml └── test ├── cockroachdb_test.dart ├── postgres_test.dart └── samples ├── sample_pg_hba.conf └── sample_postgresql.conf /.gitignore: -------------------------------------------------------------------------------- 1 | # Files and directories created by pub 2 | .dart_tool/ 3 | .packages 4 | # Remove the following pattern if you wish to check in your lock file 5 | pubspec.lock 6 | 7 | # Conventional directory for build outputs 8 | build/ 9 | 10 | # Directory created by dartdoc 11 | doc/api/ 12 | 13 | # Idea 14 | *.iml 15 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 1.3.2 2 | 3 | - Added optional `timeZone` parameter for `postgresql` start method 4 | (will fill both `TZ` and `PGTZ` environment variable). 5 | 6 | ## 1.3.1 7 | 8 | - Added new optional parameters to `startPostgres` ([#2][] by [osaxma][]): 9 | - `postgresqlConfPath` to mount a custom `postgresql.conf` file 10 | - `pgHbaConfPath` to mount a custom `pg_hba.conf` file 11 | - `configurations` to supply any individual configs (e.g. `['shared_buffers=256MB']`) 12 | 13 | [#2]: https://github.com/isoos/docker_process/pull/2 14 | [osaxma]: https://github.com/osaxma 15 | 16 | ## 1.3.0 17 | 18 | - Migrated to null safety. 19 | 20 | ## 1.2.0 21 | 22 | - Updated code to modern SDK and current lints. 23 | - `readySignal` can be async 24 | - CockroachDB extra arguments: 25 | - `attrs`: the list of attributes to set for the node 26 | - `advertiseHost` and `advertisePort` to control what the node tells about itself 27 | - `join`: the list of nodes to join 28 | - `initialize`: set to true if you want the first node to get initialized 29 | 30 | ## 1.1.2 31 | 32 | - `network` and `hostname` setting in pre-configured containers. 33 | 34 | ## 1.1.1 35 | 36 | - Helper method for running the CockroachDB container. 37 | 38 | ## 1.1.0 39 | 40 | - Helper method for running the `postgres` container. 41 | 42 | ## 1.0.0 43 | 44 | - Start and stop docker container (like a process). 45 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2018, the project authors. All rights reserved. 2 | Redistribution and use in source and binary forms, with or without 3 | modification, are permitted provided that the following conditions are 4 | met: 5 | 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above 9 | copyright notice, this list of conditions and the following 10 | disclaimer in the documentation and/or other materials provided 11 | with the distribution. 12 | * Neither the name of the project nor the names of its 13 | contributors may be used to endorse or promote products derived 14 | from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Access wrapper to interact with a docker container like a process. 2 | 3 | ## Example 4 | 5 | ````dart 6 | import 'package:docker_process/docker_process.dart'; 7 | 8 | Future main() async { 9 | final dp = await DockerProcess.start( 10 | image: 'image-name', 11 | name: 'running-name', 12 | readySignal: (line) => line.contains('Done.'), 13 | ); 14 | final pr = await dp.exec(['ls', '-l']); 15 | print(pr.stdout); 16 | await dp.stop(); 17 | } 18 | ```` 19 | -------------------------------------------------------------------------------- /analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # https://www.dartlang.org/guides/language/analysis-options 2 | include: package:lints/recommended.yaml 3 | 4 | analyzer: 5 | errors: 6 | unused_element: error 7 | unused_import: error 8 | unused_local_variable: error 9 | dead_code: error 10 | strong-mode: 11 | implicit-casts: false 12 | 13 | # Lint rules and documentation, see http://dart-lang.github.io/linter/lints 14 | linter: 15 | rules: 16 | - annotate_overrides 17 | - avoid_unused_constructor_parameters 18 | - await_only_futures 19 | - camel_case_types 20 | - cancel_subscriptions 21 | - collection_methods_unrelated_type 22 | - directives_ordering 23 | - empty_catches 24 | - empty_statements 25 | - hash_and_equals 26 | - no_adjacent_strings_in_list 27 | - no_duplicate_case_values 28 | - non_constant_identifier_names 29 | - only_throw_errors 30 | - overridden_fields 31 | - prefer_collection_literals 32 | - prefer_conditional_assignment 33 | - prefer_contains 34 | - prefer_final_fields 35 | - prefer_final_locals 36 | - prefer_initializing_formals 37 | - prefer_interpolation_to_compose_strings 38 | - prefer_is_empty 39 | - prefer_is_not_empty 40 | - prefer_single_quotes 41 | - prefer_typing_uninitialized_variables 42 | - recursive_getters 43 | - slash_for_doc_comments 44 | - test_types_in_equals 45 | - throw_in_finally 46 | - type_init_formals 47 | - unawaited_futures 48 | - unnecessary_brace_in_string_interps 49 | - unnecessary_getters_setters 50 | - unnecessary_lambdas 51 | - unnecessary_new 52 | - unnecessary_null_aware_assignments 53 | - unnecessary_statements 54 | - unnecessary_this 55 | - unrelated_type_equality_checks 56 | - use_rethrow_when_possible 57 | - valid_regexps 58 | -------------------------------------------------------------------------------- /example/example.dart: -------------------------------------------------------------------------------- 1 | import 'package:docker_process/docker_process.dart'; 2 | 3 | Future main() async { 4 | final dp = await DockerProcess.start( 5 | image: 'image-name', 6 | name: 'running-name', 7 | readySignal: (line) => line.contains('Done.'), 8 | ); 9 | final pr = await dp.exec(['ls', '-l']); 10 | print(pr.stdout); 11 | await dp.stop(); 12 | } 13 | -------------------------------------------------------------------------------- /lib/containers/cockroachdb.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | import 'package:docker_process/docker_process.dart'; 4 | 5 | export 'package:docker_process/docker_process.dart'; 6 | 7 | Future startCockroachDB({ 8 | required String name, 9 | required String version, 10 | String imageName = 'cockroachdb/cockroach', 11 | String? network, 12 | int pgPort = 26257, 13 | int httpPort = 8080, 14 | bool? cleanup, 15 | bool secure = false, 16 | bool initialize = false, 17 | List? attrs, 18 | List? join, 19 | String? advertiseHost, 20 | int? advertisePort, 21 | }) async { 22 | final isJoining = join != null && join.isNotEmpty; 23 | var starting = false; 24 | var initialized = !initialize; 25 | return await DockerProcess.start( 26 | name: name, 27 | image: '$imageName:$version', 28 | network: network, 29 | hostname: name, 30 | ports: ['$pgPort:26257', '$httpPort:8080'], 31 | cleanup: cleanup, 32 | readySignal: (line) async { 33 | if (!initialized) { 34 | if (!line.contains('cockroach init')) { 35 | return false; 36 | } 37 | final pr = await Process.run( 38 | 'docker', 39 | [ 40 | 'exec', 41 | name, 42 | './cockroach', 43 | 'init', 44 | if (!secure) '--insecure', 45 | ], 46 | ); 47 | if (pr.exitCode != 0) { 48 | throw Exception( 49 | '`docker exec $name cockroach init` failed:\n${pr.stdout}\n\n${pr.stderr}'); 50 | } 51 | initialized = true; 52 | return false; 53 | } 54 | 55 | starting |= line.contains('CockroachDB node starting'); 56 | return starting && line.contains('nodeID:'); 57 | }, 58 | imageArgs: [ 59 | 'start', 60 | if (!secure) '--insecure', 61 | if (attrs != null && attrs.isNotEmpty) ...['--attrs', attrs.join(',')], 62 | if (advertiseHost != null) '--advertise-host=$advertiseHost', 63 | if (advertisePort != null) '--advertise-port=$advertisePort', 64 | if (isJoining) ...['--join', join!.join(',')], 65 | ], 66 | ); 67 | } 68 | -------------------------------------------------------------------------------- /lib/containers/postgres.dart: -------------------------------------------------------------------------------- 1 | import 'package:docker_process/docker_process.dart'; 2 | 3 | export 'package:docker_process/docker_process.dart'; 4 | 5 | /// Starts a postgres container with the given [name] using the given 6 | /// [imageName] and [version]. 7 | /// 8 | /// Use [postgresqlConfPath] or [pgHbaConfPath] to mount `postgresql.conf` 9 | /// or `pg_hba.conf` on the container, respectively. 10 | /// 11 | /// Use [configurations] to pass list of configs to the `postgres` image. For 12 | /// example: ['shared_buffers=256MB', 'max_connections=200']. As shown, each 13 | /// item in the list must contain the parameter and its assignment in as a single 14 | /// item. 15 | /// 16 | /// For other options, please refer to [DockerProcess.start]. 17 | Future startPostgres({ 18 | required String name, 19 | required String version, 20 | String imageName = 'postgres', 21 | String? network, 22 | String? pgUser, 23 | String pgPassword = 'postgres', 24 | String? pgDatabase, 25 | int pgPort = 5432, 26 | bool? cleanup, 27 | String? postgresqlConfPath, 28 | String? pgHbaConfPath, 29 | List? configurations, 30 | String? timeZone, 31 | }) async { 32 | var ipv4 = false; 33 | 34 | final dockerArgs = []; 35 | final imageArgs = []; 36 | 37 | if (configurations != null) { 38 | for (var config in configurations) { 39 | imageArgs.add('-c'); 40 | imageArgs.add(config); 41 | } 42 | } 43 | 44 | // see Database Configuration section at official image page: 45 | // https://hub.docker.com/_/postgres/ 46 | if (postgresqlConfPath != null) { 47 | dockerArgs.add('-v'); 48 | dockerArgs.add('$postgresqlConfPath:/etc/postgresql/postgresql.conf'); 49 | 50 | imageArgs.add('-c'); 51 | imageArgs.add('config_file=/etc/postgresql/postgresql.conf'); 52 | } 53 | 54 | if (pgHbaConfPath != null) { 55 | dockerArgs.add('-v'); 56 | dockerArgs.add('$pgHbaConfPath:/etc/postgresql/pg_hba.conf'); 57 | 58 | imageArgs.add('-c'); 59 | imageArgs.add('hba_file=/etc/postgresql/pg_hba.conf'); 60 | } 61 | 62 | return await DockerProcess.start( 63 | name: name, 64 | dockerArgs: dockerArgs, 65 | image: '$imageName:$version', 66 | imageArgs: imageArgs, 67 | network: network, 68 | hostname: name, 69 | ports: ['$pgPort:5432'], 70 | cleanup: cleanup, 71 | readySignal: (line) { 72 | ipv4 |= line.contains('listening on IPv4 address "0.0.0.0", port 5432'); 73 | return ipv4 && 74 | line.contains('database system is ready to accept connections'); 75 | }, 76 | environment: { 77 | if (pgUser != null) 'POSTGRES_USER': pgUser, 78 | 'POSTGRES_PASSWORD': pgPassword, 79 | if (pgDatabase != null) 'POSTGRES_DB': pgDatabase, 80 | if (timeZone != null) 'TZ': timeZone, 81 | if (timeZone != null) 'PGTZ': timeZone, 82 | }, 83 | ); 84 | } 85 | -------------------------------------------------------------------------------- /lib/docker_process.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | import 'dart:convert'; 3 | import 'dart:io'; 4 | 5 | import 'package:logging/logging.dart'; 6 | 7 | final _logger = Logger('docker_process'); 8 | 9 | /// Access wrapper to interact with a docker container as a process. 10 | class DockerProcess { 11 | final String _dockerExecutable; 12 | final String _name; 13 | 14 | DockerProcess._(this._dockerExecutable, this._name); 15 | 16 | /// Starts a docker container. 17 | static Future start({ 18 | required String image, 19 | required String name, 20 | String? dockerExecutable, 21 | String? dockerCommand, 22 | List? dockerArgs, 23 | String? network, 24 | String? hostname, 25 | Map? environment, 26 | List? ports, 27 | List? imageArgs, 28 | bool sudo = false, 29 | bool? cleanup, 30 | FutureOr Function(String line)? readySignal, 31 | Duration? timeout, 32 | }) async { 33 | dockerExecutable ??= 'docker'; 34 | cleanup ??= false; 35 | var command = dockerExecutable; 36 | final args = []; 37 | 38 | if (sudo) { 39 | args.add(command); 40 | command = 'sudo'; 41 | } 42 | dockerCommand ??= readySignal == null ? 'start' : 'run'; 43 | 44 | args.add(dockerCommand); 45 | if (cleanup) { 46 | args.add('--rm'); 47 | } 48 | 49 | args.addAll([ 50 | '--name', 51 | name, 52 | ]); 53 | 54 | if (network != null) { 55 | args.add('--net'); 56 | args.add(network); 57 | } 58 | if (hostname != null) { 59 | args.add('-h'); 60 | args.add(hostname); 61 | } 62 | ports?.forEach((p) { 63 | args.add('-p'); 64 | args.add(p); 65 | }); 66 | environment?.forEach((k, v) { 67 | args.add('-e'); 68 | args.add('$k=$v'); 69 | }); 70 | if (dockerArgs != null && dockerArgs.isNotEmpty) { 71 | args.addAll(dockerArgs); 72 | } 73 | args.add(image); 74 | if (imageArgs != null) { 75 | args.addAll(imageArgs); 76 | } 77 | 78 | _logger.info({ 79 | 'starting': {'name': name, 'command': command, 'args': args}, 80 | }); 81 | if (readySignal != null) { 82 | final process = await Process.start(command, args); 83 | 84 | final c = Completer(); 85 | final timer = Timer(timeout ?? const Duration(minutes: 1), () { 86 | if (c.isCompleted) return; 87 | c.completeError('timeout'); 88 | }); 89 | StreamSubscription? subs1; 90 | StreamSubscription? subs2; 91 | StreamSubscription subs(Stream> stream) { 92 | return stream 93 | .transform(utf8.decoder) 94 | .transform(LineSplitter()) 95 | .listen((String line) async { 96 | if (await readySignal(line)) { 97 | await subs1?.cancel(); 98 | subs1 = null; 99 | await subs2?.cancel(); 100 | subs2 = null; 101 | if (c.isCompleted) return; 102 | c.complete(); 103 | } 104 | }); 105 | } 106 | 107 | subs1 = subs(process.stdout); 108 | subs2 = subs(process.stderr); 109 | 110 | final dp = DockerProcess._(dockerExecutable, name); 111 | 112 | try { 113 | await c.future; 114 | } catch (_) { 115 | await dp.kill(); 116 | rethrow; 117 | } finally { 118 | timer.cancel(); 119 | } 120 | return dp; 121 | } else { 122 | final pr = await Process.run(command, args); 123 | if (pr.exitCode != 0) { 124 | throw Exception( 125 | 'exitCode: ${pr.exitCode}\n\nstdout: ${pr.stdout}\n\nstderr: ${pr.stderr}'); 126 | } 127 | return DockerProcess._(dockerExecutable, name); 128 | } 129 | } 130 | 131 | /// Executes the command 132 | Future exec(List args) async { 133 | _logger.info({ 134 | 'executing': {'name': _name, 'args': args}, 135 | }); 136 | return Process.run(_dockerExecutable, ['exec', _name, ...args]); 137 | } 138 | 139 | /// Kill the docker container. 140 | Future kill({ 141 | ProcessSignal signal = ProcessSignal.sigkill, 142 | }) async { 143 | try { 144 | _logger.info({ 145 | 'killing': {'name': _name} 146 | }); 147 | await Process.run(_dockerExecutable, ['kill', '--signal=$signal', _name]); 148 | } catch (e, st) { 149 | _logger.warning({ 150 | 'kill-error': {'name': _name}, 151 | }, e, st); 152 | } 153 | } 154 | 155 | /// Stop the docker container. 156 | Future stop() async { 157 | try { 158 | _logger.info({ 159 | 'stopping': {'name': _name} 160 | }); 161 | await Process.run(_dockerExecutable, ['stop', _name]); 162 | } catch (e, st) { 163 | _logger.warning({ 164 | 'stop-error': {'name': _name}, 165 | }, e, st); 166 | } 167 | } 168 | 169 | /// Checks whether the container is running. 170 | Future isRunning() async { 171 | final pr = await Process.run( 172 | _dockerExecutable, 173 | ['ps', '--format', '{{.Names}}'], 174 | ); 175 | return pr.stdout 176 | .toString() 177 | .split('\n') 178 | .map((s) => s.trim()) 179 | .contains(_name); 180 | } 181 | } 182 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: docker_process 2 | description: Access wrapper to interact with a docker container like a process. 3 | version: 1.3.2 4 | homepage: https://github.com/isoos/docker_process 5 | 6 | environment: 7 | sdk: '>=2.12.0 <4.0.0' 8 | 9 | dependencies: 10 | logging: ^1.0.0 11 | 12 | dev_dependencies: 13 | path: ^1.8.2 14 | lints: ^4.0.0 15 | postgres: ^2.3.0-0 16 | test: ^1.0.0 17 | -------------------------------------------------------------------------------- /test/cockroachdb_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:docker_process/containers/cockroachdb.dart'; 2 | import 'package:postgres/postgres.dart'; 3 | import 'package:test/test.dart'; 4 | 5 | void main() { 6 | group('CockroachDB', () { 7 | DockerProcess? dp; 8 | 9 | tearDownAll(() async { 10 | await dp?.stop(); 11 | await dp?.kill(); 12 | }); 13 | 14 | test('run', () async { 15 | dp = await startCockroachDB( 16 | name: 'test_crdb', 17 | version: 'latest', 18 | cleanup: true, 19 | initialize: true, 20 | ); 21 | 22 | final c = PostgreSQLConnection( 23 | 'localhost', 24 | 26257, 25 | 'root', 26 | username: 'root', 27 | password: 'crdb', 28 | ); 29 | await c.open(); 30 | await c.close(); 31 | }); 32 | }); 33 | } 34 | -------------------------------------------------------------------------------- /test/postgres_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | import 'package:docker_process/containers/postgres.dart'; 4 | import 'package:path/path.dart' as p; 5 | import 'package:postgres/postgres.dart'; 6 | import 'package:test/test.dart'; 7 | 8 | final _samplesDir = p.join(Directory.current.path, 'test', 'samples'); 9 | 10 | void main() { 11 | group('postgres', () { 12 | DockerProcess? dp; 13 | 14 | tearDownAll(() async { 15 | await dp?.stop(); 16 | await dp?.kill(); 17 | }); 18 | 19 | test('run', () async { 20 | dp = await startPostgres( 21 | name: 'test_postgres', 22 | version: 'latest', 23 | cleanup: true, 24 | ); 25 | 26 | final c = PostgreSQLConnection( 27 | 'localhost', 28 | 5432, 29 | 'postgres', 30 | username: 'postgres', 31 | password: 'postgres', 32 | ); 33 | await c.open(); 34 | await c.close(); 35 | }); 36 | }); 37 | 38 | group('mounting conf files', () { 39 | DockerProcess? dp1; 40 | DockerProcess? dp2; 41 | 42 | tearDownAll(() async { 43 | await dp1?.stop(); 44 | await dp2?.stop(); 45 | await dp1?.kill(); 46 | await dp2?.kill(); 47 | }); 48 | 49 | test('mount custom postgresql.conf', () async { 50 | final postgresqlConfPath = p.join(_samplesDir, 'sample_postgresql.conf'); 51 | dp1 = await startPostgres( 52 | name: 'test_postgresql_conf_mounting', 53 | version: 'latest', 54 | cleanup: true, 55 | pgPort: 5432, 56 | postgresqlConfPath: postgresqlConfPath, 57 | ); 58 | 59 | // confirm sample_postgresql.conf is mounted correctly 60 | final res = await dp1!.exec([ 61 | 'cat', 62 | '/etc/postgresql/postgresql.conf', 63 | ]); 64 | 65 | final file = res.stdout as String; 66 | 67 | expect(file.startsWith('# sample_postgresql.conf'), true); 68 | }); 69 | 70 | test('mount custom pg_hba.conf', () async { 71 | final pgHbaConfPath = p.join(_samplesDir, 'sample_pg_hba.conf'); 72 | 73 | dp2 = await startPostgres( 74 | name: 'test_pg_hba_conf_mounting', 75 | version: 'latest', 76 | cleanup: true, 77 | // this would conflict with the other test in the group 78 | // so it's a different number 79 | pgPort: 54321, 80 | pgHbaConfPath: pgHbaConfPath, 81 | ); 82 | final res = await dp2!.exec([ 83 | 'cat', 84 | '/etc/postgresql/pg_hba.conf', 85 | ]); 86 | 87 | final file = res.stdout as String; 88 | 89 | expect(file.startsWith('# sample_pg_hba.conf'), true); 90 | }); 91 | }); 92 | 93 | group('mounting postgresql.conf is effective', () { 94 | DockerProcess? dp; 95 | 96 | tearDownAll(() async { 97 | await dp?.stop(); 98 | await dp?.kill(); 99 | }); 100 | 101 | // in the `sample_postgresql.conf`, the `wal_level` was changed to `logical` 102 | // here we test if this has taken effect after mounting the sample conf. 103 | test('wal_level should be logical', () async { 104 | final postgresqlConfPath = p.join(_samplesDir, 'sample_postgresql.conf'); 105 | dp = await startPostgres( 106 | name: 'check_wal_level', 107 | version: 'latest', 108 | cleanup: true, 109 | pgPort: 5432, 110 | postgresqlConfPath: postgresqlConfPath, 111 | ); 112 | 113 | // confirm sample_postgresql.conf is mounted correctly 114 | final c = PostgreSQLConnection( 115 | 'localhost', 116 | 5432, 117 | 'postgres', 118 | username: 'postgres', 119 | password: 'postgres', 120 | ); 121 | 122 | await c.open(); 123 | final res = await c.query('show wal_level'); 124 | expect(res.first.first, 'logical'); 125 | await c.close(); 126 | }); 127 | }); 128 | 129 | group('test postgres configuration arguments', () { 130 | DockerProcess? dp; 131 | 132 | tearDownAll(() async { 133 | await dp?.stop(); 134 | await dp?.kill(); 135 | }); 136 | 137 | test('Adding configuration arguments is reflected on the image', () async { 138 | dp = await startPostgres( 139 | name: 'test_postgresql_conf_mounting', 140 | version: 'latest', 141 | cleanup: true, 142 | pgPort: 5432, 143 | configurations: ['max_connections=42'], 144 | ); 145 | 146 | // confirm sample_postgresql.conf is mounted correctly 147 | final c = PostgreSQLConnection( 148 | 'localhost', 149 | 5432, 150 | 'postgres', 151 | username: 'postgres', 152 | password: 'postgres', 153 | ); 154 | 155 | await c.open(); 156 | final res = await c.query('show max_connections'); 157 | expect(res.first.first, '42'); 158 | await c.close(); 159 | }); 160 | }); 161 | } 162 | -------------------------------------------------------------------------------- /test/samples/sample_pg_hba.conf: -------------------------------------------------------------------------------- 1 | # sample_pg_hba.conf 2 | 3 | # NOTES: 4 | # - the first line is used for testing to verify the volume was mounted correctly. 5 | # - this file was copied from a running container of a postgres image 6 | # - the file is located at /var/lib/postgresql/data/ 7 | # - The file was generated from the following version: postgres (PostgreSQL) 14.5 (Debian 14.5-1.pgdg110+1) 8 | # 9 | 10 | # PostgreSQL Client Authentication Configuration File 11 | # =================================================== 12 | # 13 | # Refer to the "Client Authentication" section in the PostgreSQL 14 | # documentation for a complete description of this file. A short 15 | # synopsis follows. 16 | # 17 | # This file controls: which hosts are allowed to connect, how clients 18 | # are authenticated, which PostgreSQL user names they can use, which 19 | # databases they can access. Records take one of these forms: 20 | # 21 | # local DATABASE USER METHOD [OPTIONS] 22 | # host DATABASE USER ADDRESS METHOD [OPTIONS] 23 | # hostssl DATABASE USER ADDRESS METHOD [OPTIONS] 24 | # hostnossl DATABASE USER ADDRESS METHOD [OPTIONS] 25 | # hostgssenc DATABASE USER ADDRESS METHOD [OPTIONS] 26 | # hostnogssenc DATABASE USER ADDRESS METHOD [OPTIONS] 27 | # 28 | # (The uppercase items must be replaced by actual values.) 29 | # 30 | # The first field is the connection type: 31 | # - "local" is a Unix-domain socket 32 | # - "host" is a TCP/IP socket (encrypted or not) 33 | # - "hostssl" is a TCP/IP socket that is SSL-encrypted 34 | # - "hostnossl" is a TCP/IP socket that is not SSL-encrypted 35 | # - "hostgssenc" is a TCP/IP socket that is GSSAPI-encrypted 36 | # - "hostnogssenc" is a TCP/IP socket that is not GSSAPI-encrypted 37 | # 38 | # DATABASE can be "all", "sameuser", "samerole", "replication", a 39 | # database name, or a comma-separated list thereof. The "all" 40 | # keyword does not match "replication". Access to replication 41 | # must be enabled in a separate record (see example below). 42 | # 43 | # USER can be "all", a user name, a group name prefixed with "+", or a 44 | # comma-separated list thereof. In both the DATABASE and USER fields 45 | # you can also write a file name prefixed with "@" to include names 46 | # from a separate file. 47 | # 48 | # ADDRESS specifies the set of hosts the record matches. It can be a 49 | # host name, or it is made up of an IP address and a CIDR mask that is 50 | # an integer (between 0 and 32 (IPv4) or 128 (IPv6) inclusive) that 51 | # specifies the number of significant bits in the mask. A host name 52 | # that starts with a dot (.) matches a suffix of the actual host name. 53 | # Alternatively, you can write an IP address and netmask in separate 54 | # columns to specify the set of hosts. Instead of a CIDR-address, you 55 | # can write "samehost" to match any of the server's own IP addresses, 56 | # or "samenet" to match any address in any subnet that the server is 57 | # directly connected to. 58 | # 59 | # METHOD can be "trust", "reject", "md5", "password", "scram-sha-256", 60 | # "gss", "sspi", "ident", "peer", "pam", "ldap", "radius" or "cert". 61 | # Note that "password" sends passwords in clear text; "md5" or 62 | # "scram-sha-256" are preferred since they send encrypted passwords. 63 | # 64 | # OPTIONS are a set of options for the authentication in the format 65 | # NAME=VALUE. The available options depend on the different 66 | # authentication methods -- refer to the "Client Authentication" 67 | # section in the documentation for a list of which options are 68 | # available for which authentication methods. 69 | # 70 | # Database and user names containing spaces, commas, quotes and other 71 | # special characters must be quoted. Quoting one of the keywords 72 | # "all", "sameuser", "samerole" or "replication" makes the name lose 73 | # its special character, and just match a database or username with 74 | # that name. 75 | # 76 | # This file is read on server startup and when the server receives a 77 | # SIGHUP signal. If you edit the file on a running system, you have to 78 | # SIGHUP the server for the changes to take effect, run "pg_ctl reload", 79 | # or execute "SELECT pg_reload_conf()". 80 | # 81 | # Put your actual configuration here 82 | # ---------------------------------- 83 | # 84 | # If you want to allow non-local connections, you need to add more 85 | # "host" records. In that case you will also need to make PostgreSQL 86 | # listen on a non-local interface via the listen_addresses 87 | # configuration parameter, or via the -i or -h command line switches. 88 | 89 | # CAUTION: Configuring the system for local "trust" authentication 90 | # allows any local user to connect as any PostgreSQL user, including 91 | # the database superuser. If you do not trust all your local users, 92 | # use another authentication method. 93 | 94 | 95 | # TYPE DATABASE USER ADDRESS METHOD 96 | 97 | # "local" is for Unix domain socket connections only 98 | local all all trust 99 | # IPv4 local connections: 100 | host all all 127.0.0.1/32 trust 101 | # IPv6 local connections: 102 | host all all ::1/128 trust 103 | # Allow replication connections from localhost, by a user with the 104 | # replication privilege. 105 | local replication all trust 106 | host replication all 127.0.0.1/32 trust 107 | host replication all ::1/128 trust 108 | 109 | host all all all scram-sha-256 -------------------------------------------------------------------------------- /test/samples/sample_postgresql.conf: -------------------------------------------------------------------------------- 1 | # sample_postgresql.conf 2 | 3 | # NOTES: 4 | # - The first line is used in testing to verify the file was mounted correctly. 5 | # - The `wal_level` was changed to `logical` for testing purposes as well. All other configs were left as is. 6 | # - The file was generated from the following version: postgres (PostgreSQL) 14.5 (Debian 14.5-1.pgdg110+1) 7 | # - This file can be generated from a postgres image by running the following: 8 | # ``` 9 | # docker run -i --rm postgres cat /usr/share/postgresql/postgresql.conf.sample > ~/path/to/folder/custom_postgresql.conf 10 | # ``` 11 | # "--rm" means it'll remove the contianer automatically after the command is executed. 12 | 13 | # ----------------------------- 14 | # PostgreSQL configuration file 15 | # ----------------------------- 16 | # 17 | # This file consists of lines of the form: 18 | # 19 | # name = value 20 | # 21 | # (The "=" is optional.) Whitespace may be used. Comments are introduced with 22 | # "#" anywhere on a line. The complete list of parameter names and allowed 23 | # values can be found in the PostgreSQL documentation. 24 | # 25 | # The commented-out settings shown in this file represent the default values. 26 | # Re-commenting a setting is NOT sufficient to revert it to the default value; 27 | # you need to reload the server. 28 | # 29 | # This file is read on server startup and when the server receives a SIGHUP 30 | # signal. If you edit the file on a running system, you have to SIGHUP the 31 | # server for the changes to take effect, run "pg_ctl reload", or execute 32 | # "SELECT pg_reload_conf()". Some parameters, which are marked below, 33 | # require a server shutdown and restart to take effect. 34 | # 35 | # Any parameter can also be given as a command-line option to the server, e.g., 36 | # "postgres -c log_connections=on". Some parameters can be changed at run time 37 | # with the "SET" SQL command. 38 | # 39 | # Memory units: B = bytes Time units: us = microseconds 40 | # kB = kilobytes ms = milliseconds 41 | # MB = megabytes s = seconds 42 | # GB = gigabytes min = minutes 43 | # TB = terabytes h = hours 44 | # d = days 45 | 46 | 47 | #------------------------------------------------------------------------------ 48 | # FILE LOCATIONS 49 | #------------------------------------------------------------------------------ 50 | 51 | # The default values of these variables are driven from the -D command-line 52 | # option or PGDATA environment variable, represented here as ConfigDir. 53 | 54 | #data_directory = 'ConfigDir' # use data in another directory 55 | # (change requires restart) 56 | #hba_file = 'ConfigDir/pg_hba.conf' # host-based authentication file 57 | # (change requires restart) 58 | #ident_file = 'ConfigDir/pg_ident.conf' # ident configuration file 59 | # (change requires restart) 60 | 61 | # If external_pid_file is not explicitly set, no extra PID file is written. 62 | #external_pid_file = '' # write an extra PID file 63 | # (change requires restart) 64 | 65 | 66 | #------------------------------------------------------------------------------ 67 | # CONNECTIONS AND AUTHENTICATION 68 | #------------------------------------------------------------------------------ 69 | 70 | # - Connection Settings - 71 | 72 | listen_addresses = '*' 73 | # comma-separated list of addresses; 74 | # defaults to 'localhost'; use '*' for all 75 | # (change requires restart) 76 | #port = 5432 # (change requires restart) 77 | #max_connections = 100 # (change requires restart) 78 | #superuser_reserved_connections = 3 # (change requires restart) 79 | #unix_socket_directories = '/tmp' # comma-separated list of directories 80 | # (change requires restart) 81 | #unix_socket_group = '' # (change requires restart) 82 | #unix_socket_permissions = 0777 # begin with 0 to use octal notation 83 | # (change requires restart) 84 | #bonjour = off # advertise server via Bonjour 85 | # (change requires restart) 86 | #bonjour_name = '' # defaults to the computer name 87 | # (change requires restart) 88 | 89 | # - TCP settings - 90 | # see "man tcp" for details 91 | 92 | #tcp_keepalives_idle = 0 # TCP_KEEPIDLE, in seconds; 93 | # 0 selects the system default 94 | #tcp_keepalives_interval = 0 # TCP_KEEPINTVL, in seconds; 95 | # 0 selects the system default 96 | #tcp_keepalives_count = 0 # TCP_KEEPCNT; 97 | # 0 selects the system default 98 | #tcp_user_timeout = 0 # TCP_USER_TIMEOUT, in milliseconds; 99 | # 0 selects the system default 100 | 101 | #client_connection_check_interval = 0 # time between checks for client 102 | # disconnection while running queries; 103 | # 0 for never 104 | 105 | # - Authentication - 106 | 107 | #authentication_timeout = 1min # 1s-600s 108 | #password_encryption = scram-sha-256 # scram-sha-256 or md5 109 | #db_user_namespace = off 110 | 111 | # GSSAPI using Kerberos 112 | #krb_server_keyfile = 'FILE:${sysconfdir}/krb5.keytab' 113 | #krb_caseins_users = off 114 | 115 | # - SSL - 116 | 117 | #ssl = off 118 | #ssl_ca_file = '' 119 | #ssl_cert_file = 'server.crt' 120 | #ssl_crl_file = '' 121 | #ssl_crl_dir = '' 122 | #ssl_key_file = 'server.key' 123 | #ssl_ciphers = 'HIGH:MEDIUM:+3DES:!aNULL' # allowed SSL ciphers 124 | #ssl_prefer_server_ciphers = on 125 | #ssl_ecdh_curve = 'prime256v1' 126 | #ssl_min_protocol_version = 'TLSv1.2' 127 | #ssl_max_protocol_version = '' 128 | #ssl_dh_params_file = '' 129 | #ssl_passphrase_command = '' 130 | #ssl_passphrase_command_supports_reload = off 131 | 132 | 133 | #------------------------------------------------------------------------------ 134 | # RESOURCE USAGE (except WAL) 135 | #------------------------------------------------------------------------------ 136 | 137 | # - Memory - 138 | 139 | #shared_buffers = 32MB # min 128kB 140 | # (change requires restart) 141 | #huge_pages = try # on, off, or try 142 | # (change requires restart) 143 | #huge_page_size = 0 # zero for system default 144 | # (change requires restart) 145 | #temp_buffers = 8MB # min 800kB 146 | #max_prepared_transactions = 0 # zero disables the feature 147 | # (change requires restart) 148 | # Caution: it is not advisable to set max_prepared_transactions nonzero unless 149 | # you actively intend to use prepared transactions. 150 | #work_mem = 4MB # min 64kB 151 | #hash_mem_multiplier = 1.0 # 1-1000.0 multiplier on hash table work_mem 152 | #maintenance_work_mem = 64MB # min 1MB 153 | #autovacuum_work_mem = -1 # min 1MB, or -1 to use maintenance_work_mem 154 | #logical_decoding_work_mem = 64MB # min 64kB 155 | #max_stack_depth = 2MB # min 100kB 156 | #shared_memory_type = mmap # the default is the first option 157 | # supported by the operating system: 158 | # mmap 159 | # sysv 160 | # windows 161 | # (change requires restart) 162 | #dynamic_shared_memory_type = posix # the default is the first option 163 | # supported by the operating system: 164 | # posix 165 | # sysv 166 | # windows 167 | # mmap 168 | # (change requires restart) 169 | #min_dynamic_shared_memory = 0MB # (change requires restart) 170 | 171 | # - Disk - 172 | 173 | #temp_file_limit = -1 # limits per-process temp file space 174 | # in kilobytes, or -1 for no limit 175 | 176 | # - Kernel Resources - 177 | 178 | #max_files_per_process = 1000 # min 64 179 | # (change requires restart) 180 | 181 | # - Cost-Based Vacuum Delay - 182 | 183 | #vacuum_cost_delay = 0 # 0-100 milliseconds (0 disables) 184 | #vacuum_cost_page_hit = 1 # 0-10000 credits 185 | #vacuum_cost_page_miss = 2 # 0-10000 credits 186 | #vacuum_cost_page_dirty = 20 # 0-10000 credits 187 | #vacuum_cost_limit = 200 # 1-10000 credits 188 | 189 | # - Background Writer - 190 | 191 | #bgwriter_delay = 200ms # 10-10000ms between rounds 192 | #bgwriter_lru_maxpages = 100 # max buffers written/round, 0 disables 193 | #bgwriter_lru_multiplier = 2.0 # 0-10.0 multiplier on buffers scanned/round 194 | #bgwriter_flush_after = 0 # measured in pages, 0 disables 195 | 196 | # - Asynchronous Behavior - 197 | 198 | #backend_flush_after = 0 # measured in pages, 0 disables 199 | #effective_io_concurrency = 1 # 1-1000; 0 disables prefetching 200 | #maintenance_io_concurrency = 10 # 1-1000; 0 disables prefetching 201 | #max_worker_processes = 8 # (change requires restart) 202 | #max_parallel_workers_per_gather = 2 # taken from max_parallel_workers 203 | #max_parallel_maintenance_workers = 2 # taken from max_parallel_workers 204 | #max_parallel_workers = 8 # maximum number of max_worker_processes that 205 | # can be used in parallel operations 206 | #parallel_leader_participation = on 207 | #old_snapshot_threshold = -1 # 1min-60d; -1 disables; 0 is immediate 208 | # (change requires restart) 209 | 210 | 211 | #------------------------------------------------------------------------------ 212 | # WRITE-AHEAD LOG 213 | #------------------------------------------------------------------------------ 214 | 215 | # - Settings - 216 | 217 | wal_level = logical # minimal, replica, or logical 218 | # (change requires restart) 219 | #fsync = on # flush data to disk for crash safety 220 | # (turning this off can cause 221 | # unrecoverable data corruption) 222 | #synchronous_commit = on # synchronization level; 223 | # off, local, remote_write, remote_apply, or on 224 | #wal_sync_method = fsync # the default is the first option 225 | # supported by the operating system: 226 | # open_datasync 227 | # fdatasync (default on Linux and FreeBSD) 228 | # fsync 229 | # fsync_writethrough 230 | # open_sync 231 | #full_page_writes = on # recover from partial page writes 232 | #wal_log_hints = off # also do full page writes of non-critical updates 233 | # (change requires restart) 234 | #wal_compression = off # enable compression of full-page writes 235 | #wal_init_zero = on # zero-fill new WAL files 236 | #wal_recycle = on # recycle WAL files 237 | #wal_buffers = -1 # min 32kB, -1 sets based on shared_buffers 238 | # (change requires restart) 239 | #wal_writer_delay = 200ms # 1-10000 milliseconds 240 | #wal_writer_flush_after = 1MB # measured in pages, 0 disables 241 | #wal_skip_threshold = 2MB 242 | 243 | #commit_delay = 0 # range 0-100000, in microseconds 244 | #commit_siblings = 5 # range 1-1000 245 | 246 | # - Checkpoints - 247 | 248 | #checkpoint_timeout = 5min # range 30s-1d 249 | #checkpoint_completion_target = 0.9 # checkpoint target duration, 0.0 - 1.0 250 | #checkpoint_flush_after = 0 # measured in pages, 0 disables 251 | #checkpoint_warning = 30s # 0 disables 252 | #max_wal_size = 1GB 253 | #min_wal_size = 80MB 254 | 255 | # - Archiving - 256 | 257 | #archive_mode = off # enables archiving; off, on, or always 258 | # (change requires restart) 259 | #archive_command = '' # command to use to archive a logfile segment 260 | # placeholders: %p = path of file to archive 261 | # %f = file name only 262 | # e.g. 'test ! -f /mnt/server/archivedir/%f && cp %p /mnt/server/archivedir/%f' 263 | #archive_timeout = 0 # force a logfile segment switch after this 264 | # number of seconds; 0 disables 265 | 266 | # - Archive Recovery - 267 | 268 | # These are only used in recovery mode. 269 | 270 | #restore_command = '' # command to use to restore an archived logfile segment 271 | # placeholders: %p = path of file to restore 272 | # %f = file name only 273 | # e.g. 'cp /mnt/server/archivedir/%f %p' 274 | #archive_cleanup_command = '' # command to execute at every restartpoint 275 | #recovery_end_command = '' # command to execute at completion of recovery 276 | 277 | # - Recovery Target - 278 | 279 | # Set these only when performing a targeted recovery. 280 | 281 | #recovery_target = '' # 'immediate' to end recovery as soon as a 282 | # consistent state is reached 283 | # (change requires restart) 284 | #recovery_target_name = '' # the named restore point to which recovery will proceed 285 | # (change requires restart) 286 | #recovery_target_time = '' # the time stamp up to which recovery will proceed 287 | # (change requires restart) 288 | #recovery_target_xid = '' # the transaction ID up to which recovery will proceed 289 | # (change requires restart) 290 | #recovery_target_lsn = '' # the WAL LSN up to which recovery will proceed 291 | # (change requires restart) 292 | #recovery_target_inclusive = on # Specifies whether to stop: 293 | # just after the specified recovery target (on) 294 | # just before the recovery target (off) 295 | # (change requires restart) 296 | #recovery_target_timeline = 'latest' # 'current', 'latest', or timeline ID 297 | # (change requires restart) 298 | #recovery_target_action = 'pause' # 'pause', 'promote', 'shutdown' 299 | # (change requires restart) 300 | 301 | 302 | #------------------------------------------------------------------------------ 303 | # REPLICATION 304 | #------------------------------------------------------------------------------ 305 | 306 | # - Sending Servers - 307 | 308 | # Set these on the primary and on any standby that will send replication data. 309 | 310 | #max_wal_senders = 10 # max number of walsender processes 311 | # (change requires restart) 312 | #max_replication_slots = 10 # max number of replication slots 313 | # (change requires restart) 314 | #wal_keep_size = 0 # in megabytes; 0 disables 315 | #max_slot_wal_keep_size = -1 # in megabytes; -1 disables 316 | #wal_sender_timeout = 60s # in milliseconds; 0 disables 317 | #track_commit_timestamp = off # collect timestamp of transaction commit 318 | # (change requires restart) 319 | 320 | # - Primary Server - 321 | 322 | # These settings are ignored on a standby server. 323 | 324 | #synchronous_standby_names = '' # standby servers that provide sync rep 325 | # method to choose sync standbys, number of sync standbys, 326 | # and comma-separated list of application_name 327 | # from standby(s); '*' = all 328 | #vacuum_defer_cleanup_age = 0 # number of xacts by which cleanup is delayed 329 | 330 | # - Standby Servers - 331 | 332 | # These settings are ignored on a primary server. 333 | 334 | #primary_conninfo = '' # connection string to sending server 335 | #primary_slot_name = '' # replication slot on sending server 336 | #promote_trigger_file = '' # file name whose presence ends recovery 337 | #hot_standby = on # "off" disallows queries during recovery 338 | # (change requires restart) 339 | #max_standby_archive_delay = 30s # max delay before canceling queries 340 | # when reading WAL from archive; 341 | # -1 allows indefinite delay 342 | #max_standby_streaming_delay = 30s # max delay before canceling queries 343 | # when reading streaming WAL; 344 | # -1 allows indefinite delay 345 | #wal_receiver_create_temp_slot = off # create temp slot if primary_slot_name 346 | # is not set 347 | #wal_receiver_status_interval = 10s # send replies at least this often 348 | # 0 disables 349 | #hot_standby_feedback = off # send info from standby to prevent 350 | # query conflicts 351 | #wal_receiver_timeout = 60s # time that receiver waits for 352 | # communication from primary 353 | # in milliseconds; 0 disables 354 | #wal_retrieve_retry_interval = 5s # time to wait before retrying to 355 | # retrieve WAL after a failed attempt 356 | #recovery_min_apply_delay = 0 # minimum delay for applying changes during recovery 357 | 358 | # - Subscribers - 359 | 360 | # These settings are ignored on a publisher. 361 | 362 | #max_logical_replication_workers = 4 # taken from max_worker_processes 363 | # (change requires restart) 364 | #max_sync_workers_per_subscription = 2 # taken from max_logical_replication_workers 365 | 366 | 367 | #------------------------------------------------------------------------------ 368 | # QUERY TUNING 369 | #------------------------------------------------------------------------------ 370 | 371 | # - Planner Method Configuration - 372 | 373 | #enable_async_append = on 374 | #enable_bitmapscan = on 375 | #enable_gathermerge = on 376 | #enable_hashagg = on 377 | #enable_hashjoin = on 378 | #enable_incremental_sort = on 379 | #enable_indexscan = on 380 | #enable_indexonlyscan = on 381 | #enable_material = on 382 | #enable_memoize = on 383 | #enable_mergejoin = on 384 | #enable_nestloop = on 385 | #enable_parallel_append = on 386 | #enable_parallel_hash = on 387 | #enable_partition_pruning = on 388 | #enable_partitionwise_join = off 389 | #enable_partitionwise_aggregate = off 390 | #enable_seqscan = on 391 | #enable_sort = on 392 | #enable_tidscan = on 393 | 394 | # - Planner Cost Constants - 395 | 396 | #seq_page_cost = 1.0 # measured on an arbitrary scale 397 | #random_page_cost = 4.0 # same scale as above 398 | #cpu_tuple_cost = 0.01 # same scale as above 399 | #cpu_index_tuple_cost = 0.005 # same scale as above 400 | #cpu_operator_cost = 0.0025 # same scale as above 401 | #parallel_setup_cost = 1000.0 # same scale as above 402 | #parallel_tuple_cost = 0.1 # same scale as above 403 | #min_parallel_table_scan_size = 8MB 404 | #min_parallel_index_scan_size = 512kB 405 | #effective_cache_size = 4GB 406 | 407 | #jit_above_cost = 100000 # perform JIT compilation if available 408 | # and query more expensive than this; 409 | # -1 disables 410 | #jit_inline_above_cost = 500000 # inline small functions if query is 411 | # more expensive than this; -1 disables 412 | #jit_optimize_above_cost = 500000 # use expensive JIT optimizations if 413 | # query is more expensive than this; 414 | # -1 disables 415 | 416 | # - Genetic Query Optimizer - 417 | 418 | #geqo = on 419 | #geqo_threshold = 12 420 | #geqo_effort = 5 # range 1-10 421 | #geqo_pool_size = 0 # selects default based on effort 422 | #geqo_generations = 0 # selects default based on effort 423 | #geqo_selection_bias = 2.0 # range 1.5-2.0 424 | #geqo_seed = 0.0 # range 0.0-1.0 425 | 426 | # - Other Planner Options - 427 | 428 | #default_statistics_target = 100 # range 1-10000 429 | #constraint_exclusion = partition # on, off, or partition 430 | #cursor_tuple_fraction = 0.1 # range 0.0-1.0 431 | #from_collapse_limit = 8 432 | #jit = on # allow JIT compilation 433 | #join_collapse_limit = 8 # 1 disables collapsing of explicit 434 | # JOIN clauses 435 | #plan_cache_mode = auto # auto, force_generic_plan or 436 | # force_custom_plan 437 | 438 | 439 | #------------------------------------------------------------------------------ 440 | # REPORTING AND LOGGING 441 | #------------------------------------------------------------------------------ 442 | 443 | # - Where to Log - 444 | 445 | #log_destination = 'stderr' # Valid values are combinations of 446 | # stderr, csvlog, syslog, and eventlog, 447 | # depending on platform. csvlog 448 | # requires logging_collector to be on. 449 | 450 | # This is used when logging to stderr: 451 | #logging_collector = off # Enable capturing of stderr and csvlog 452 | # into log files. Required to be on for 453 | # csvlogs. 454 | # (change requires restart) 455 | 456 | # These are only used if logging_collector is on: 457 | #log_directory = 'log' # directory where log files are written, 458 | # can be absolute or relative to PGDATA 459 | #log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' # log file name pattern, 460 | # can include strftime() escapes 461 | #log_file_mode = 0600 # creation mode for log files, 462 | # begin with 0 to use octal notation 463 | #log_rotation_age = 1d # Automatic rotation of logfiles will 464 | # happen after that time. 0 disables. 465 | #log_rotation_size = 10MB # Automatic rotation of logfiles will 466 | # happen after that much log output. 467 | # 0 disables. 468 | #log_truncate_on_rotation = off # If on, an existing log file with the 469 | # same name as the new log file will be 470 | # truncated rather than appended to. 471 | # But such truncation only occurs on 472 | # time-driven rotation, not on restarts 473 | # or size-driven rotation. Default is 474 | # off, meaning append to existing files 475 | # in all cases. 476 | 477 | # These are relevant when logging to syslog: 478 | #syslog_facility = 'LOCAL0' 479 | #syslog_ident = 'postgres' 480 | #syslog_sequence_numbers = on 481 | #syslog_split_messages = on 482 | 483 | # This is only relevant when logging to eventlog (Windows): 484 | # (change requires restart) 485 | #event_source = 'PostgreSQL' 486 | 487 | # - When to Log - 488 | 489 | #log_min_messages = warning # values in order of decreasing detail: 490 | # debug5 491 | # debug4 492 | # debug3 493 | # debug2 494 | # debug1 495 | # info 496 | # notice 497 | # warning 498 | # error 499 | # log 500 | # fatal 501 | # panic 502 | 503 | #log_min_error_statement = error # values in order of decreasing detail: 504 | # debug5 505 | # debug4 506 | # debug3 507 | # debug2 508 | # debug1 509 | # info 510 | # notice 511 | # warning 512 | # error 513 | # log 514 | # fatal 515 | # panic (effectively off) 516 | 517 | #log_min_duration_statement = -1 # -1 is disabled, 0 logs all statements 518 | # and their durations, > 0 logs only 519 | # statements running at least this number 520 | # of milliseconds 521 | 522 | #log_min_duration_sample = -1 # -1 is disabled, 0 logs a sample of statements 523 | # and their durations, > 0 logs only a sample of 524 | # statements running at least this number 525 | # of milliseconds; 526 | # sample fraction is determined by log_statement_sample_rate 527 | 528 | #log_statement_sample_rate = 1.0 # fraction of logged statements exceeding 529 | # log_min_duration_sample to be logged; 530 | # 1.0 logs all such statements, 0.0 never logs 531 | 532 | 533 | #log_transaction_sample_rate = 0.0 # fraction of transactions whose statements 534 | # are logged regardless of their duration; 1.0 logs all 535 | # statements from all transactions, 0.0 never logs 536 | 537 | # - What to Log - 538 | 539 | #debug_print_parse = off 540 | #debug_print_rewritten = off 541 | #debug_print_plan = off 542 | #debug_pretty_print = on 543 | #log_autovacuum_min_duration = -1 # log autovacuum activity; 544 | # -1 disables, 0 logs all actions and 545 | # their durations, > 0 logs only 546 | # actions running at least this number 547 | # of milliseconds. 548 | #log_checkpoints = off 549 | #log_connections = off 550 | #log_disconnections = off 551 | #log_duration = off 552 | #log_error_verbosity = default # terse, default, or verbose messages 553 | #log_hostname = off 554 | #log_line_prefix = '%m [%p] ' # special values: 555 | # %a = application name 556 | # %u = user name 557 | # %d = database name 558 | # %r = remote host and port 559 | # %h = remote host 560 | # %b = backend type 561 | # %p = process ID 562 | # %P = process ID of parallel group leader 563 | # %t = timestamp without milliseconds 564 | # %m = timestamp with milliseconds 565 | # %n = timestamp with milliseconds (as a Unix epoch) 566 | # %Q = query ID (0 if none or not computed) 567 | # %i = command tag 568 | # %e = SQL state 569 | # %c = session ID 570 | # %l = session line number 571 | # %s = session start timestamp 572 | # %v = virtual transaction ID 573 | # %x = transaction ID (0 if none) 574 | # %q = stop here in non-session 575 | # processes 576 | # %% = '%' 577 | # e.g. '<%u%%%d> ' 578 | #log_lock_waits = off # log lock waits >= deadlock_timeout 579 | #log_recovery_conflict_waits = off # log standby recovery conflict waits 580 | # >= deadlock_timeout 581 | #log_parameter_max_length = -1 # when logging statements, limit logged 582 | # bind-parameter values to N bytes; 583 | # -1 means print in full, 0 disables 584 | #log_parameter_max_length_on_error = 0 # when logging an error, limit logged 585 | # bind-parameter values to N bytes; 586 | # -1 means print in full, 0 disables 587 | #log_statement = 'none' # none, ddl, mod, all 588 | #log_replication_commands = off 589 | #log_temp_files = -1 # log temporary files equal or larger 590 | # than the specified size in kilobytes; 591 | # -1 disables, 0 logs all temp files 592 | #log_timezone = 'GMT' 593 | 594 | 595 | #------------------------------------------------------------------------------ 596 | # PROCESS TITLE 597 | #------------------------------------------------------------------------------ 598 | 599 | #cluster_name = '' # added to process titles if nonempty 600 | # (change requires restart) 601 | #update_process_title = on 602 | 603 | 604 | #------------------------------------------------------------------------------ 605 | # STATISTICS 606 | #------------------------------------------------------------------------------ 607 | 608 | # - Query and Index Statistics Collector - 609 | 610 | #track_activities = on 611 | #track_activity_query_size = 1024 # (change requires restart) 612 | #track_counts = on 613 | #track_io_timing = off 614 | #track_wal_io_timing = off 615 | #track_functions = none # none, pl, all 616 | #stats_temp_directory = 'pg_stat_tmp' 617 | 618 | 619 | # - Monitoring - 620 | 621 | #compute_query_id = auto 622 | #log_statement_stats = off 623 | #log_parser_stats = off 624 | #log_planner_stats = off 625 | #log_executor_stats = off 626 | 627 | 628 | #------------------------------------------------------------------------------ 629 | # AUTOVACUUM 630 | #------------------------------------------------------------------------------ 631 | 632 | #autovacuum = on # Enable autovacuum subprocess? 'on' 633 | # requires track_counts to also be on. 634 | #autovacuum_max_workers = 3 # max number of autovacuum subprocesses 635 | # (change requires restart) 636 | #autovacuum_naptime = 1min # time between autovacuum runs 637 | #autovacuum_vacuum_threshold = 50 # min number of row updates before 638 | # vacuum 639 | #autovacuum_vacuum_insert_threshold = 1000 # min number of row inserts 640 | # before vacuum; -1 disables insert 641 | # vacuums 642 | #autovacuum_analyze_threshold = 50 # min number of row updates before 643 | # analyze 644 | #autovacuum_vacuum_scale_factor = 0.2 # fraction of table size before vacuum 645 | #autovacuum_vacuum_insert_scale_factor = 0.2 # fraction of inserts over table 646 | # size before insert vacuum 647 | #autovacuum_analyze_scale_factor = 0.1 # fraction of table size before analyze 648 | #autovacuum_freeze_max_age = 200000000 # maximum XID age before forced vacuum 649 | # (change requires restart) 650 | #autovacuum_multixact_freeze_max_age = 400000000 # maximum multixact age 651 | # before forced vacuum 652 | # (change requires restart) 653 | #autovacuum_vacuum_cost_delay = 2ms # default vacuum cost delay for 654 | # autovacuum, in milliseconds; 655 | # -1 means use vacuum_cost_delay 656 | #autovacuum_vacuum_cost_limit = -1 # default vacuum cost limit for 657 | # autovacuum, -1 means use 658 | # vacuum_cost_limit 659 | 660 | 661 | #------------------------------------------------------------------------------ 662 | # CLIENT CONNECTION DEFAULTS 663 | #------------------------------------------------------------------------------ 664 | 665 | # - Statement Behavior - 666 | 667 | #client_min_messages = notice # values in order of decreasing detail: 668 | # debug5 669 | # debug4 670 | # debug3 671 | # debug2 672 | # debug1 673 | # log 674 | # notice 675 | # warning 676 | # error 677 | #search_path = '"$user", public' # schema names 678 | #row_security = on 679 | #default_table_access_method = 'heap' 680 | #default_tablespace = '' # a tablespace name, '' uses the default 681 | #default_toast_compression = 'pglz' # 'pglz' or 'lz4' 682 | #temp_tablespaces = '' # a list of tablespace names, '' uses 683 | # only default tablespace 684 | #check_function_bodies = on 685 | #default_transaction_isolation = 'read committed' 686 | #default_transaction_read_only = off 687 | #default_transaction_deferrable = off 688 | #session_replication_role = 'origin' 689 | #statement_timeout = 0 # in milliseconds, 0 is disabled 690 | #lock_timeout = 0 # in milliseconds, 0 is disabled 691 | #idle_in_transaction_session_timeout = 0 # in milliseconds, 0 is disabled 692 | #idle_session_timeout = 0 # in milliseconds, 0 is disabled 693 | #vacuum_freeze_table_age = 150000000 694 | #vacuum_freeze_min_age = 50000000 695 | #vacuum_failsafe_age = 1600000000 696 | #vacuum_multixact_freeze_table_age = 150000000 697 | #vacuum_multixact_freeze_min_age = 5000000 698 | #vacuum_multixact_failsafe_age = 1600000000 699 | #bytea_output = 'hex' # hex, escape 700 | #xmlbinary = 'base64' 701 | #xmloption = 'content' 702 | #gin_pending_list_limit = 4MB 703 | 704 | # - Locale and Formatting - 705 | 706 | #datestyle = 'iso, mdy' 707 | #intervalstyle = 'postgres' 708 | #timezone = 'GMT' 709 | #timezone_abbreviations = 'Default' # Select the set of available time zone 710 | # abbreviations. Currently, there are 711 | # Default 712 | # Australia (historical usage) 713 | # India 714 | # You can create your own file in 715 | # share/timezonesets/. 716 | #extra_float_digits = 1 # min -15, max 3; any value >0 actually 717 | # selects precise output mode 718 | #client_encoding = sql_ascii # actually, defaults to database 719 | # encoding 720 | 721 | # These settings are initialized by initdb, but they can be changed. 722 | #lc_messages = 'C' # locale for system error message 723 | # strings 724 | #lc_monetary = 'C' # locale for monetary formatting 725 | #lc_numeric = 'C' # locale for number formatting 726 | #lc_time = 'C' # locale for time formatting 727 | 728 | # default configuration for text search 729 | #default_text_search_config = 'pg_catalog.simple' 730 | 731 | # - Shared Library Preloading - 732 | 733 | #local_preload_libraries = '' 734 | #session_preload_libraries = '' 735 | #shared_preload_libraries = '' # (change requires restart) 736 | #jit_provider = 'llvmjit' # JIT library to use 737 | 738 | # - Other Defaults - 739 | 740 | #dynamic_library_path = '$libdir' 741 | #extension_destdir = '' # prepend path when loading extensions 742 | # and shared objects (added by Debian) 743 | #gin_fuzzy_search_limit = 0 744 | 745 | 746 | #------------------------------------------------------------------------------ 747 | # LOCK MANAGEMENT 748 | #------------------------------------------------------------------------------ 749 | 750 | #deadlock_timeout = 1s 751 | #max_locks_per_transaction = 64 # min 10 752 | # (change requires restart) 753 | #max_pred_locks_per_transaction = 64 # min 10 754 | # (change requires restart) 755 | #max_pred_locks_per_relation = -2 # negative values mean 756 | # (max_pred_locks_per_transaction 757 | # / -max_pred_locks_per_relation) - 1 758 | #max_pred_locks_per_page = 2 # min 0 759 | 760 | 761 | #------------------------------------------------------------------------------ 762 | # VERSION AND PLATFORM COMPATIBILITY 763 | #------------------------------------------------------------------------------ 764 | 765 | # - Previous PostgreSQL Versions - 766 | 767 | #array_nulls = on 768 | #backslash_quote = safe_encoding # on, off, or safe_encoding 769 | #escape_string_warning = on 770 | #lo_compat_privileges = off 771 | #quote_all_identifiers = off 772 | #standard_conforming_strings = on 773 | #synchronize_seqscans = on 774 | 775 | # - Other Platforms and Clients - 776 | 777 | #transform_null_equals = off 778 | 779 | 780 | #------------------------------------------------------------------------------ 781 | # ERROR HANDLING 782 | #------------------------------------------------------------------------------ 783 | 784 | #exit_on_error = off # terminate session on any error? 785 | #restart_after_crash = on # reinitialize after backend crash? 786 | #data_sync_retry = off # retry or panic on failure to fsync 787 | # data? 788 | # (change requires restart) 789 | #recovery_init_sync_method = fsync # fsync, syncfs (Linux 5.8+) 790 | 791 | 792 | #------------------------------------------------------------------------------ 793 | # CONFIG FILE INCLUDES 794 | #------------------------------------------------------------------------------ 795 | 796 | # These options allow settings to be loaded from files other than the 797 | # default postgresql.conf. Note that these are directives, not variable 798 | # assignments, so they can usefully be given more than once. 799 | 800 | #include_dir = '...' # include files ending in '.conf' from 801 | # a directory, e.g., 'conf.d' 802 | #include_if_exists = '...' # include file only if it exists 803 | #include = '...' # include file 804 | 805 | 806 | #------------------------------------------------------------------------------ 807 | # CUSTOMIZED OPTIONS 808 | #------------------------------------------------------------------------------ 809 | 810 | # Add settings for extensions here 811 | --------------------------------------------------------------------------------