pgsql: Add pg_get_tablespace_ddl() function

Started by Andrew Dunstan3 months ago1 messagescomitters
Jump to latest
#1Andrew Dunstan
andrew@dunslane.net

Add pg_get_tablespace_ddl() function

Add a new SQL-callable function that returns the DDL statements needed
to recreate a tablespace. It takes a tablespace name or OID and an
optional VARIADIC text argument for options that are specified as
alternating name/value pairs. The following options are supported: pretty
(boolean) for formatted output and owner (boolean) to include OWNER.
(It includes two variants because there is no regtablespace pseudotype.)
The return is one or multiple rows where the first row is a CREATE
TABLESPACE statement and subsequent rows are ALTER TABLESPACE statements
to set some tablespace properties.

The caller must have SELECT privilege on pg_tablespace.

get_reloptions() in ruleutils.c is made non-static so it can be called
from the new ddlutils.c file.

Author: Nishant Sharma <nishant.sharma@enterprisedb.com>
Author: Manni Wood <manni.wood@enterprisedb.com>
Co-authored-by: Andrew Dunstan <andrew@dunslane.net>
Co-authored-by: Euler Taveira <euler@eulerto.com>
Reviewed-by: Jim Jones <jim.jones@uni-muenster.de>
Reviewed-by: Álvaro Herrera <alvherre@kurilemu.de>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: /messages/by-id/CAKWEB6rmnmGKUA87Zmq-s=b3Scsnj02C0kObQjnbL2ajfPWGEw@mail.gmail.com
Discussion: /messages/by-id/e247c261-e3fb-4810-81e0-a65893170e94@dunslane.net

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/b99fd9fd7f363c6363f4c8a95c699b9134b0357f

Modified Files
--------------
doc/src/sgml/func/func-info.sgml | 28 ++++
src/backend/utils/adt/ddlutils.c | 206 ++++++++++++++++++++++++++-
src/backend/utils/adt/ruleutils.c | 4 +-
src/include/catalog/pg_proc.dat | 16 +++
src/include/utils/ruleutils.h | 1 +
src/test/regress/expected/tablespace_ddl.out | 84 +++++++++++
src/test/regress/parallel_schedule | 2 +-
src/test/regress/sql/tablespace_ddl.sql | 58 ++++++++
8 files changed, 395 insertions(+), 4 deletions(-)