Docs menu

Docs

Database users

Applies to prodmask Pro 1.0.0-beta.2

prodmask needs two users: one that reads the source, and one that writes staging.

The source user, for the database shop:

GRANT SELECT, SHOW VIEW ON `shop`.* TO 'prodmask_ro'@'%';
GRANT PROCESS ON *.* TO 'prodmask_ro'@'%';

PROCESS lets the copy see a session that waits on its snapshot, and end the snapshot, so a copy never holds up production's work. On MySQL, GRANT SELECT ON performance_schema.* serves instead. Without either, a copy from a replica only warns, and one from a primary is refused.

A copy that stops can't hold production up for long. The copy also ends its snapshot when it gets old. The limit is 15 minutes by default on a writable source. On a replica there's a limit only when you give --max-snapshot-age.

The watchdog runs in the copy's own process, so whatever suspends the process suspends it too: Ctrl-Z, a paused container or VM, a debugger. So wherever there's a limit, the copy also has the source's server end the snapshot's session itself, once the session has waited for the copy that long plus 30 seconds. It does that with wait_timeout between statements, and with net_write_timeout, at most 30 minutes, while rows wait to be taken. A suspended copy then loses its session, and production its locks, after at most twice the limit and 30 seconds.

  • A writable source whose server doesn't keep those two settings is refused, with exit status 1: "refusing to copy from a writable source: its server didn't take the time limits on the snapshot's session (wait_timeout and net_write_timeout), so a copy that stopped could keep production's locks. Copy from a replica". Copy from a replica instead.
  • On a replica given --max-snapshot-age, the same case only warns: "the source's server didn't take the time limits on the snapshot's session, so a copy that stopped would keep its locks past --max-snapshot-age".
  • A writable source whose server's own maximum wait_timeout is below --max-snapshot-age is refused, with exit status 1. That maximum is a year, or about 24 days on Windows. The refusal reads "refusing to copy from a writable source: its server keeps the time limits on the snapshot's session (wait_timeout and net_write_timeout) below --max-snapshot-age, at its own maximum. Copy from a replica, or lower --max-snapshot-age". Copy from a replica, or lower --max-snapshot-age.
  • On a replica, the same case only warns: "the source's server keeps the time limits on the snapshot's session below --max-snapshot-age, at its own maximum".
  • After a suspension, the copy stops with exit status 1: "stopped the copy: it had stopped for longer than the snapshot's age limit (--max-snapshot-age), so the source's server ended the snapshot's session, and its locks on production with it. Run the copy again". It says so even when its watchdog wakes first, or was checking when the copy stopped.

How prodmask reads the source. Besides the fixed statements the database driver sends as it connects, every statement scan and plan send to the source is checked to be a read before it reaches the server. copy reads the source's schema and rows through the same checker. The checker refuses control characters outside strings and quoted names, character set changes in a SET other than SET NAMES with utf8mb4, utf8mb3, utf8 or binary, and calls that change a MariaDB sequence. A statement it refuses is a fault in prodmask, and prodmask says so: "prodmask stopped a statement it was about to send, because it isn't a read: this is a fault in prodmask, please report it". plan and copy stop there, with exit status 1, and scan gives it as its reason for the table it was reading. Tell us at support@prodmask.com.

For all three, a session variable in the source's DSN, or a character set or collation other than utf8mb4's, is ignored. A warning names it, or counts it where its name isn't a plain word, as in "the DSN's session variables aren't used: sql_big_selects"; plan gives it as source_dsn_variables. scan, leak-check, plan, copy and prune turn sql_big_selects on in their own sessions, so a server whose max_join_size is below its default doesn't stop them, and a source DSN that still carries sql_big_selects=1 can drop it. A target's DSN keeps its session variables.

The target user, for the database shop_staging:

GRANT ALL PRIVILEGES ON `shop_staging`.* TO 'prodmask_rw'@'%';
GRANT ALL PRIVILEGES ON `shop\_staging\_\_prodmask\_%`.* TO 'prodmask_rw'@'%';
GRANT REPLICATION CLIENT ON *.* TO 'prodmask_rw'@'%';

On MariaDB, write SLAVE MONITOR in place of REPLICATION CLIENT. The second grant lets the copy build in a staging schema of its own beside the target; without it, the copy builds as prefixed tables inside shop_staging. The third lets it read the target's replication status, so it can refuse a target that is a replica. Without it the copy refuses, since the target may be one: "refusing to copy: couldn't read the target's replication status, so it may be a replica. Grant the target user REPLICATION CLIENT, or SELECT on performance_schema, or pass --allow-unknown-replication". On MariaDB it names SLAVE MONITOR. --allow-unknown-replication goes on with a warning; prune already had the same flag.

The copy refuses a target on the source's server, unless you give --same-server to copy into another database there; one whose host isn't given with --allow-host or in prodmask.yml's target.allow_hosts; and a target database that isn't absent, empty or an earlier prodmask copy.

It also refuses a target that is a running replica, of the source or of any other server: "refusing to copy: the target is a running replica (it replicates from another server)", or "…the target replicates from the source". A replica counts as running unless each channel's receiver and applier are stopped, and a state prodmask doesn't know counts as running; group replication's own channels don't count. --same-server doesn't exempt it, so a scratch copy into another database on a replica's own server is refused while its replication runs: copy to another server.

If the target's server reports its replication status without a column prodmask reads, as a release that renamed one would, the copy refuses: "refusing to copy: couldn't tell whether the target is a replica: its SHOW REPLICA STATUS has no Replica_IO_Running column. Pass --allow-unknown-replication, or update prodmask". The statement and the column vary. prune refuses the same way. prune on a writable group replication member, which it refused before, now goes on.