Skip to content

pg_start_sql

runs SQL statement at instance start

pg_start_sql · runs SQL statement at instance start

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
101630pg_start_sqlpg_start_sql1.0ADMINPostgreSQLC

PostgreSQL · 9.5, 9.6, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19

Usage

Sources:

pg_start_sql runs configured SQL when a PostgreSQL instance starts. The reviewed control/installation SQL is 1.0.0; upstream reports testing on PostgreSQL 9.5–19. All startup statements run as a superuser, with no setting to choose a less privileged execution role.

Configure Startup SQL

Add the library to the existing preload list and configure the target database and statement:

shared_preload_libraries = 'pg_start_sql'
pg_start_sql.dbname = 'postgres'
pg_start_sql.stmt = 'SELECT 1'

Restart PostgreSQL for preload, and follow upstream’s extension setup:

CREATE EXTENSION pg_start_sql;

The worker is instance-wide; the extension need not be created in every database. pg_start_sql.dbname defaults to postgres. At least one of pg_start_sql.stmt or pg_start_sql.file must be configured; the latter selects a file containing startup statements.

Operational Boundary

Restrict configuration and SQL-file writes to trusted administrators because the statements execute with superuser privileges. Use startup work that is safe to repeat across server starts and verify its result and server logs. Preserve other preloaded libraries. The control file permits relocation of SQL objects, but that does not remove the cluster-level preload and restart requirements.

Table reader