Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "\restrict" mean in a psql dump? [closed]

Tags:

postgresql

I recently installed Odoo using a PostgreSQL database, and did a backup. I opened the resulting sql file, and find a directive I have never seen before: \restrict. I googled it, but I did not find anything about that. These are the first lines:

--
-- PostgreSQL database dump
--

\restrict 0ERux6q5ehfyr0ivymjWMSHEbHR7WHLkvpOyXaJui5TXdFnOEHlJteh8qxZwxzV

-- Dumped from database version 17.6 (Debian 17.6-1.pgdg13+1)
-- Dumped by pg_dump version 17.6 (Debian 17.6-1.pgdg13+1)
like image 726
Campanita Avatar asked Oct 19 '25 13:10

Campanita


1 Answers

a directive I have never seen before: \restrict. I googled it, but I did not find anything about that

It is documented in https://www.postgresql.org/docs/17/app-psql.html, alongside the related \unrestrict meta-command:

\restrict restrict_key
Enter "restricted" mode with the provided key. In this mode, the only allowed meta-command is \unrestrict, to exit restricted mode. The key may contain only alphanumeric characters.

This command is primarily intended for use in plain-text dumps generated by pg_dump, pg_dumpall, and pg_restore, but it may be useful elsewhere

\unrestrict restrict_key
Exit "restricted" mode (i.e., where all other meta-commands are blocked), provided the specified key matches the one given to \restrict when restricted mode was entered.

This command is primarily intended for use in plain-text dumps generated by pg_dump, pg_dumpall, and pg_restore, but it may be useful elsewhere.

As @AdrianKlaver noted in the comments, this was added in release 17.6 to mitigate a security issue when pg_dump is run against an untrusted database server (controlled by a malicious superuser). This could have resulted in a sql script containing malicious meta-commands that psql would have executed when it interpreted that script to restore the database.

like image 169
Bergi Avatar answered Oct 22 '25 03:10

Bergi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!