Skip to content
block_copy_command

block_copy_command

block_copy_command : Block COPY commands via a configurable ProcessUtility hook

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
7405
block_copy_command
block_copy_command
0.1.5
SEC
BSD 3-Clause
Rust
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--sLd--
No
Yes
Yes
Yes
no
no

Requires shared_preload_libraries = block_copy_command.

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXT
PIGSTY
0.1.5
18
17
16
15
14
block_copy_command-
RPM
PIGSTY
0.1.5
18
17
16
15
14
block_copy_command_$v-
DEB
PIGSTY
0.1.5
18
17
16
15
14
postgresql-$v-block-copy-command-
Linux / PGPG18PG17PG16PG15PG14
el8.x86_64
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
el8.aarch64
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
el9.x86_64
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
el9.aarch64
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
el10.x86_64
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
el10.aarch64
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
d12.x86_64
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
d12.aarch64
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
d13.x86_64
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
d13.aarch64
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
u22.x86_64
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
u22.aarch64
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
u24.x86_64
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
u24.aarch64
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
u26.x86_64
MISS
MISS
MISS
MISS
MISS
u26.aarch64
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
PIGSTY 0.1.5
PackageVersionOSORGSIZEFile URL
block_copy_command_180.1.5el8.x86_64pigsty306.1 KiBblock_copy_command_18-0.1.5-1PIGSTY.el8.x86_64.rpm
block_copy_command_180.1.5el8.aarch64pigsty199.0 KiBblock_copy_command_18-0.1.5-1PIGSTY.el8.aarch64.rpm
block_copy_command_180.1.5el9.x86_64pigsty321.7 KiBblock_copy_command_18-0.1.5-1PIGSTY.el9.x86_64.rpm
block_copy_command_180.1.5el9.aarch64pigsty212.1 KiBblock_copy_command_18-0.1.5-1PIGSTY.el9.aarch64.rpm
block_copy_command_180.1.5el10.x86_64pigsty321.9 KiBblock_copy_command_18-0.1.5-1PIGSTY.el10.x86_64.rpm
block_copy_command_180.1.5el10.aarch64pigsty212.1 KiBblock_copy_command_18-0.1.5-1PIGSTY.el10.aarch64.rpm
postgresql-18-block-copy-command0.1.5d12.x86_64pigsty248.3 KiBpostgresql-18-block-copy-command_0.1.5-1PIGSTY~bookworm_amd64.deb
postgresql-18-block-copy-command0.1.5d12.aarch64pigsty149.9 KiBpostgresql-18-block-copy-command_0.1.5-1PIGSTY~bookworm_arm64.deb
postgresql-18-block-copy-command0.1.5d13.x86_64pigsty248.3 KiBpostgresql-18-block-copy-command_0.1.5-1PIGSTY~trixie_amd64.deb
postgresql-18-block-copy-command0.1.5d13.aarch64pigsty149.9 KiBpostgresql-18-block-copy-command_0.1.5-1PIGSTY~trixie_arm64.deb
postgresql-18-block-copy-command0.1.5u22.x86_64pigsty281.0 KiBpostgresql-18-block-copy-command_0.1.5-1PIGSTY~jammy_amd64.deb
postgresql-18-block-copy-command0.1.5u22.aarch64pigsty173.9 KiBpostgresql-18-block-copy-command_0.1.5-1PIGSTY~jammy_arm64.deb
postgresql-18-block-copy-command0.1.5u24.x86_64pigsty278.5 KiBpostgresql-18-block-copy-command_0.1.5-1PIGSTY~noble_amd64.deb
postgresql-18-block-copy-command0.1.5u24.aarch64pigsty172.4 KiBpostgresql-18-block-copy-command_0.1.5-1PIGSTY~noble_arm64.deb
postgresql-18-block-copy-command0.1.5u26.aarch64pigsty178.6 KiBpostgresql-18-block-copy-command_0.1.5-2PIGSTY~resolute_arm64.deb

Source

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 via package name, for the active PG version

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
pig install block_copy_command -v 14;   # install for PG 14

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.

Last updated on