Skip to content

block_copy_command

Block COPY commands via a configurable ProcessUtility hook

block_copy_command · Block COPY commands via a configurable ProcessUtility hook

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
7440block_copy_commandblock_copy_command0.1.5SECBSD-3-ClauseRust
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--sLd--NoYesYesYesnono
Requires shared_preload_libraries = block_copy_command.

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXTPIGSTY0.1.519 18 17 16 15block_copy_command-
RPMPIGSTY0.1.519 18 17 16 15block_copy_command_$v-
DEBPIGSTY0.1.519 18 17 16 15postgresql-$v-block-copy-command-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5
el8.aarch64N/APIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5
el9.x86_64PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5
el9.aarch64PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5
el10.x86_64PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5
el10.aarch64PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5
d12.x86_64PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5
d12.aarch64PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5
d13.x86_64PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5
d13.aarch64PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5
u22.x86_64PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5
u22.aarch64PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5
u24.x86_64PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5
u24.aarch64PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5
u26.x86_64PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5
u26.aarch64PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5PIGSTY 0.1.5
PackageVersionOSORGSIZEFile URL
block_copy_command_190.1.5el9.x86_64pigsty885.9 KiBblock_copy_command_19-0.1.5-4PGSTY.el9.x86_64.rpm
block_copy_command_190.1.5el9.aarch64pigsty857.0 KiBblock_copy_command_19-0.1.5-4PGSTY.el9.aarch64.rpm
block_copy_command_190.1.5el10.x86_64pigsty886.5 KiBblock_copy_command_19-0.1.5-4PGSTY.el10.x86_64.rpm
block_copy_command_190.1.5el10.aarch64pigsty856.5 KiBblock_copy_command_19-0.1.5-4PGSTY.el10.aarch64.rpm
postgresql-19-block-copy-command0.1.5d12.x86_64pigsty595.2 KiBpostgresql-19-block-copy-command_0.1.5-4PGSTY~bookworm_amd64.deb
postgresql-19-block-copy-command0.1.5d12.aarch64pigsty520.8 KiBpostgresql-19-block-copy-command_0.1.5-4PGSTY~bookworm_arm64.deb
postgresql-19-block-copy-command0.1.5d13.x86_64pigsty595.7 KiBpostgresql-19-block-copy-command_0.1.5-4PGSTY~trixie_amd64.deb
postgresql-19-block-copy-command0.1.5d13.aarch64pigsty520.9 KiBpostgresql-19-block-copy-command_0.1.5-4PGSTY~trixie_arm64.deb
postgresql-19-block-copy-command0.1.5u22.x86_64pigsty663.0 KiBpostgresql-19-block-copy-command_0.1.5-4PGSTY~jammy_amd64.deb
postgresql-19-block-copy-command0.1.5u22.aarch64pigsty615.4 KiBpostgresql-19-block-copy-command_0.1.5-4PGSTY~jammy_arm64.deb
postgresql-19-block-copy-command0.1.5u24.x86_64pigsty653.8 KiBpostgresql-19-block-copy-command_0.1.5-4PGSTY~noble_amd64.deb
postgresql-19-block-copy-command0.1.5u24.aarch64pigsty607.8 KiBpostgresql-19-block-copy-command_0.1.5-4PGSTY~noble_arm64.deb
postgresql-19-block-copy-command0.1.5u26.x86_64pigsty651.8 KiBpostgresql-19-block-copy-command_0.1.5-4PGSTY~resolute_amd64.deb
postgresql-19-block-copy-command0.1.5u26.aarch64pigsty606.4 KiBpostgresql-19-block-copy-command_0.1.5-4PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
block_copy_command_180.1.5el8.x86_64pigsty857.1 KiBblock_copy_command_18-0.1.5-3PIGSTY.el8.x86_64.rpm
block_copy_command_180.1.5el8.aarch64pigsty771.0 KiBblock_copy_command_18-0.1.5-3PIGSTY.el8.aarch64.rpm
block_copy_command_180.1.5el9.x86_64pigsty880.9 KiBblock_copy_command_18-0.1.5-4PGSTY.el9.x86_64.rpm
block_copy_command_180.1.5el9.aarch64pigsty850.9 KiBblock_copy_command_18-0.1.5-4PGSTY.el9.aarch64.rpm
block_copy_command_180.1.5el10.x86_64pigsty881.4 KiBblock_copy_command_18-0.1.5-4PGSTY.el10.x86_64.rpm
block_copy_command_180.1.5el10.aarch64pigsty850.5 KiBblock_copy_command_18-0.1.5-4PGSTY.el10.aarch64.rpm
postgresql-18-block-copy-command0.1.5d12.x86_64pigsty592.9 KiBpostgresql-18-block-copy-command_0.1.5-4PGSTY~bookworm_amd64.deb
postgresql-18-block-copy-command0.1.5d12.aarch64pigsty517.9 KiBpostgresql-18-block-copy-command_0.1.5-4PGSTY~bookworm_arm64.deb
postgresql-18-block-copy-command0.1.5d13.x86_64pigsty593.0 KiBpostgresql-18-block-copy-command_0.1.5-4PGSTY~trixie_amd64.deb
postgresql-18-block-copy-command0.1.5d13.aarch64pigsty518.2 KiBpostgresql-18-block-copy-command_0.1.5-4PGSTY~trixie_arm64.deb
postgresql-18-block-copy-command0.1.5u22.x86_64pigsty660.0 KiBpostgresql-18-block-copy-command_0.1.5-4PGSTY~jammy_amd64.deb
postgresql-18-block-copy-command0.1.5u22.aarch64pigsty613.3 KiBpostgresql-18-block-copy-command_0.1.5-4PGSTY~jammy_arm64.deb
postgresql-18-block-copy-command0.1.5u24.x86_64pigsty652.2 KiBpostgresql-18-block-copy-command_0.1.5-4PGSTY~noble_amd64.deb
postgresql-18-block-copy-command0.1.5u24.aarch64pigsty606.0 KiBpostgresql-18-block-copy-command_0.1.5-4PGSTY~noble_arm64.deb
postgresql-18-block-copy-command0.1.5u26.x86_64pigsty648.6 KiBpostgresql-18-block-copy-command_0.1.5-4PGSTY~resolute_amd64.deb
postgresql-18-block-copy-command0.1.5u26.aarch64pigsty603.6 KiBpostgresql-18-block-copy-command_0.1.5-4PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
block_copy_command_170.1.5el8.x86_64pigsty854.4 KiBblock_copy_command_17-0.1.5-3PIGSTY.el8.x86_64.rpm
block_copy_command_170.1.5el8.aarch64pigsty767.8 KiBblock_copy_command_17-0.1.5-3PIGSTY.el8.aarch64.rpm
block_copy_command_170.1.5el9.x86_64pigsty876.2 KiBblock_copy_command_17-0.1.5-4PGSTY.el9.x86_64.rpm
block_copy_command_170.1.5el9.aarch64pigsty846.3 KiBblock_copy_command_17-0.1.5-4PGSTY.el9.aarch64.rpm
block_copy_command_170.1.5el10.x86_64pigsty876.8 KiBblock_copy_command_17-0.1.5-4PGSTY.el10.x86_64.rpm
block_copy_command_170.1.5el10.aarch64pigsty848.0 KiBblock_copy_command_17-0.1.5-4PGSTY.el10.aarch64.rpm
postgresql-17-block-copy-command0.1.5d12.x86_64pigsty589.9 KiBpostgresql-17-block-copy-command_0.1.5-4PGSTY~bookworm_amd64.deb
postgresql-17-block-copy-command0.1.5d12.aarch64pigsty517.1 KiBpostgresql-17-block-copy-command_0.1.5-4PGSTY~bookworm_arm64.deb
postgresql-17-block-copy-command0.1.5d13.x86_64pigsty589.9 KiBpostgresql-17-block-copy-command_0.1.5-4PGSTY~trixie_amd64.deb
postgresql-17-block-copy-command0.1.5d13.aarch64pigsty516.3 KiBpostgresql-17-block-copy-command_0.1.5-4PGSTY~trixie_arm64.deb
postgresql-17-block-copy-command0.1.5u22.x86_64pigsty656.6 KiBpostgresql-17-block-copy-command_0.1.5-4PGSTY~jammy_amd64.deb
postgresql-17-block-copy-command0.1.5u22.aarch64pigsty611.1 KiBpostgresql-17-block-copy-command_0.1.5-4PGSTY~jammy_arm64.deb
postgresql-17-block-copy-command0.1.5u24.x86_64pigsty649.5 KiBpostgresql-17-block-copy-command_0.1.5-4PGSTY~noble_amd64.deb
postgresql-17-block-copy-command0.1.5u24.aarch64pigsty604.1 KiBpostgresql-17-block-copy-command_0.1.5-4PGSTY~noble_arm64.deb
postgresql-17-block-copy-command0.1.5u26.x86_64pigsty645.5 KiBpostgresql-17-block-copy-command_0.1.5-4PGSTY~resolute_amd64.deb
postgresql-17-block-copy-command0.1.5u26.aarch64pigsty601.6 KiBpostgresql-17-block-copy-command_0.1.5-4PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
block_copy_command_160.1.5el8.x86_64pigsty854.0 KiBblock_copy_command_16-0.1.5-3PIGSTY.el8.x86_64.rpm
block_copy_command_160.1.5el8.aarch64pigsty766.4 KiBblock_copy_command_16-0.1.5-3PIGSTY.el8.aarch64.rpm
block_copy_command_160.1.5el9.x86_64pigsty874.3 KiBblock_copy_command_16-0.1.5-4PGSTY.el9.x86_64.rpm
block_copy_command_160.1.5el9.aarch64pigsty844.6 KiBblock_copy_command_16-0.1.5-4PGSTY.el9.aarch64.rpm
block_copy_command_160.1.5el10.x86_64pigsty873.7 KiBblock_copy_command_16-0.1.5-4PGSTY.el10.x86_64.rpm
block_copy_command_160.1.5el10.aarch64pigsty844.6 KiBblock_copy_command_16-0.1.5-4PGSTY.el10.aarch64.rpm
postgresql-16-block-copy-command0.1.5d12.x86_64pigsty589.6 KiBpostgresql-16-block-copy-command_0.1.5-4PGSTY~bookworm_amd64.deb
postgresql-16-block-copy-command0.1.5d12.aarch64pigsty515.9 KiBpostgresql-16-block-copy-command_0.1.5-4PGSTY~bookworm_arm64.deb
postgresql-16-block-copy-command0.1.5d13.x86_64pigsty589.0 KiBpostgresql-16-block-copy-command_0.1.5-4PGSTY~trixie_amd64.deb
postgresql-16-block-copy-command0.1.5d13.aarch64pigsty515.9 KiBpostgresql-16-block-copy-command_0.1.5-4PGSTY~trixie_arm64.deb
postgresql-16-block-copy-command0.1.5u22.x86_64pigsty657.1 KiBpostgresql-16-block-copy-command_0.1.5-4PGSTY~jammy_amd64.deb
postgresql-16-block-copy-command0.1.5u22.aarch64pigsty609.7 KiBpostgresql-16-block-copy-command_0.1.5-4PGSTY~jammy_arm64.deb
postgresql-16-block-copy-command0.1.5u24.x86_64pigsty647.7 KiBpostgresql-16-block-copy-command_0.1.5-4PGSTY~noble_amd64.deb
postgresql-16-block-copy-command0.1.5u24.aarch64pigsty602.4 KiBpostgresql-16-block-copy-command_0.1.5-4PGSTY~noble_arm64.deb
postgresql-16-block-copy-command0.1.5u26.x86_64pigsty644.4 KiBpostgresql-16-block-copy-command_0.1.5-4PGSTY~resolute_amd64.deb
postgresql-16-block-copy-command0.1.5u26.aarch64pigsty599.9 KiBpostgresql-16-block-copy-command_0.1.5-4PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
block_copy_command_150.1.5el8.x86_64pigsty843.9 KiBblock_copy_command_15-0.1.5-3PIGSTY.el8.x86_64.rpm
block_copy_command_150.1.5el8.aarch64pigsty757.3 KiBblock_copy_command_15-0.1.5-3PIGSTY.el8.aarch64.rpm
block_copy_command_150.1.5el9.x86_64pigsty866.7 KiBblock_copy_command_15-0.1.5-4PGSTY.el9.x86_64.rpm
block_copy_command_150.1.5el9.aarch64pigsty836.3 KiBblock_copy_command_15-0.1.5-4PGSTY.el9.aarch64.rpm
block_copy_command_150.1.5el10.x86_64pigsty867.4 KiBblock_copy_command_15-0.1.5-4PGSTY.el10.x86_64.rpm
block_copy_command_150.1.5el10.aarch64pigsty836.6 KiBblock_copy_command_15-0.1.5-4PGSTY.el10.aarch64.rpm
postgresql-15-block-copy-command0.1.5d12.x86_64pigsty586.3 KiBpostgresql-15-block-copy-command_0.1.5-4PGSTY~bookworm_amd64.deb
postgresql-15-block-copy-command0.1.5d12.aarch64pigsty512.0 KiBpostgresql-15-block-copy-command_0.1.5-4PGSTY~bookworm_arm64.deb
postgresql-15-block-copy-command0.1.5d13.x86_64pigsty586.4 KiBpostgresql-15-block-copy-command_0.1.5-4PGSTY~trixie_amd64.deb
postgresql-15-block-copy-command0.1.5d13.aarch64pigsty512.6 KiBpostgresql-15-block-copy-command_0.1.5-4PGSTY~trixie_arm64.deb
postgresql-15-block-copy-command0.1.5u22.x86_64pigsty654.0 KiBpostgresql-15-block-copy-command_0.1.5-4PGSTY~jammy_amd64.deb
postgresql-15-block-copy-command0.1.5u22.aarch64pigsty607.2 KiBpostgresql-15-block-copy-command_0.1.5-4PGSTY~jammy_arm64.deb
postgresql-15-block-copy-command0.1.5u24.x86_64pigsty644.3 KiBpostgresql-15-block-copy-command_0.1.5-4PGSTY~noble_amd64.deb
postgresql-15-block-copy-command0.1.5u24.aarch64pigsty598.1 KiBpostgresql-15-block-copy-command_0.1.5-4PGSTY~noble_arm64.deb
postgresql-15-block-copy-command0.1.5u26.x86_64pigsty640.6 KiBpostgresql-15-block-copy-command_0.1.5-4PGSTY~resolute_amd64.deb
postgresql-15-block-copy-command0.1.5u26.aarch64pigsty596.6 KiBpostgresql-15-block-copy-command_0.1.5-4PGSTY~resolute_arm64.deb

Source

github.com/rustwizard/block_copy_command

pig build pkg block_copy_command;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install block_copy_command;		# install by package name

pig install block_copy_command -v 19;   # install for PG 19
pig install block_copy_command -v 18;   # install for PG 18
pig install block_copy_command -v 17;   # install for PG 17
pig install block_copy_command -v 16;   # install for PG 16
pig install block_copy_command -v 15;   # install for PG 15

Config this extension to shared_preload_libraries:

shared_preload_libraries = 'block_copy_command';

Create this extension with:

CREATE EXTENSION block_copy_command;

Usage

block_copy_command installs a ProcessUtility hook that intercepts COPY statements. The hook is cluster-wide once the library is loaded, while CREATE EXTENSION only registers metadata in a database.

Enable It

shared_preload_libraries = 'block_copy_command'
CREATE EXTENSION block_copy_command;

Blocking Rules

By default, non-superusers cannot run COPY TO or COPY FROM:

COPY my_table TO STDOUT;
COPY my_table FROM STDIN;
COPY (SELECT * FROM my_table) TO '/tmp/out.csv';

Priority is documented as:

  • block_copy_command.blocked_roles: always blocked, even superusers.
  • block_copy_command.block_program = on: blocks COPY ... PROGRAM for everyone.
  • block_copy_command.enabled = off: allows COPY for roles not in blocked_roles.
  • Superusers otherwise bypass direction blocking.
  • block_copy_command.block_to and block_copy_command.block_from control export/import blocking for non-superusers.

Main Settings

  • block_copy_command.enabled: master switch for non-superuser blocking.
  • block_copy_command.block_to: block COPY TO.
  • block_copy_command.block_from: block COPY FROM.
  • block_copy_command.block_program: block COPY TO/FROM PROGRAM for all users.
  • block_copy_command.hint: append a custom HINT to blocked-command errors.
  • block_copy_command.blocked_roles: comma-separated always-blocked roles.
  • block_copy_command.audit_log_enabled: write intercepted events to the audit table.

Audit And Caveats

Allowed and blocked attempts are intercepted, and the extension defines block_copy_command.audit_log plus server-log entries for blocked events. The README notes one important caveat: blocked audit rows are inserted before the error is raised, so they are rolled back with the transaction. In practice, PostgreSQL server logs are the authoritative record for blocked COPY attempts.

Table reader