Load the extension

Once the extension is installed on the host server, you need to load it into your PostgreSQL instance and then create it inside your database.

This page is the same whatever the installation method you used.

Step 1: Load the extension

The anon library must be preloaded by PostgreSQL. The recommended way is to load it globally with shared_preload_libraries:

ALTER SYSTEM SET shared_preload_libraries = 'anon';

Then restart the PostgreSQL instance.

This loads anon for every backend, including background workers. In particular it is required for Replica Masking, whose masking runs inside the logical-replication apply workers — and those workers do not read session_preload_libraries.

Alternative: session_preload_libraries

If you cannot restart the instance, or you want to enable anon on a per-database basis only, load it with session_preload_libraries instead:

ALTER DATABASE foo SET session_preload_libraries = 'anon';

(If you already load extensions that way, just add anon to the list.)

This method has its own benefits:

  • it applies to the next connections, so no restart is needed — you just have to reconnect ;
  • it is dumped by pg_dump with the -C option, so the database dump is self-contained ;
  • it is propagated to a standby by streaming replication.

Warning

session_preload_libraries does not cover background workers, so it is not enough for Replica Masking. Use shared_preload_libraries if you need it.

Step 2: Create the extension

Close your session and open a new one (so the library is loaded), then create the extension inside your database:

CREATE EXTENSION anon;
SELECT anon.init();

anon.init() loads the dataset required by the fake_* faking functions.

All new connections to that database can now use the extension.