2015-03-09 14:49:10 +01:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* dbcommands_xlog.h
|
|
|
|
* Database resource manager XLOG definitions (create/drop database).
|
|
|
|
*
|
|
|
|
*
|
2022-01-08 01:04:57 +01:00
|
|
|
* Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
|
2015-03-09 14:49:10 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
|
|
|
* src/include/commands/dbcommands_xlog.h
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef DBCOMMANDS_XLOG_H
|
|
|
|
#define DBCOMMANDS_XLOG_H
|
|
|
|
|
|
|
|
#include "access/xlogreader.h"
|
|
|
|
#include "lib/stringinfo.h"
|
|
|
|
|
|
|
|
/* record types */
|
Add new block-by-block strategy for CREATE DATABASE.
Because this strategy logs changes on a block-by-block basis, it
avoids the need to checkpoint before and after the operation.
However, because it logs each changed block individually, it might
generate a lot of extra write-ahead logging if the template database
is large. Therefore, the older strategy remains available via a new
STRATEGY parameter to CREATE DATABASE, and a corresponding --strategy
option to createdb.
Somewhat controversially, this patch assembles the list of relations
to be copied to the new database by reading the pg_class relation of
the template database. Cross-database access like this isn't normally
possible, but it can be made to work here because there can't be any
connections to the database being copied, nor can it contain any
in-doubt transactions. Even so, we have to use lower-level interfaces
than normal, since the table scan and relcache interfaces will not
work for a database to which we're not connected. The advantage of
this approach is that we do not need to rely on the filesystem to
determine what ought to be copied, but instead on PostgreSQL's own
knowledge of the database structure. This avoids, for example,
copying stray files that happen to be located in the source database
directory.
Dilip Kumar, with a fairly large number of cosmetic changes by me.
Reviewed and tested by Ashutosh Sharma, Andres Freund, John Naylor,
Greg Nancarrow, Neha Sharma. Additional feedback from Bruce Momjian,
Heikki Linnakangas, Julien Rouhaud, Adam Brusselback, Kyotaro
Horiguchi, Tomas Vondra, Andrew Dunstan, Álvaro Herrera, and others.
Discussion: http://postgr.es/m/CA+TgmoYtcdxBjLh31DLxUXHxFVMPGzrU5_T=CYCvRyFHywSBUQ@mail.gmail.com
2022-03-29 17:31:43 +02:00
|
|
|
#define XLOG_DBASE_CREATE_FILE_COPY 0x00
|
|
|
|
#define XLOG_DBASE_CREATE_WAL_LOG 0x10
|
|
|
|
#define XLOG_DBASE_DROP 0x20
|
2015-03-09 14:49:10 +01:00
|
|
|
|
Add new block-by-block strategy for CREATE DATABASE.
Because this strategy logs changes on a block-by-block basis, it
avoids the need to checkpoint before and after the operation.
However, because it logs each changed block individually, it might
generate a lot of extra write-ahead logging if the template database
is large. Therefore, the older strategy remains available via a new
STRATEGY parameter to CREATE DATABASE, and a corresponding --strategy
option to createdb.
Somewhat controversially, this patch assembles the list of relations
to be copied to the new database by reading the pg_class relation of
the template database. Cross-database access like this isn't normally
possible, but it can be made to work here because there can't be any
connections to the database being copied, nor can it contain any
in-doubt transactions. Even so, we have to use lower-level interfaces
than normal, since the table scan and relcache interfaces will not
work for a database to which we're not connected. The advantage of
this approach is that we do not need to rely on the filesystem to
determine what ought to be copied, but instead on PostgreSQL's own
knowledge of the database structure. This avoids, for example,
copying stray files that happen to be located in the source database
directory.
Dilip Kumar, with a fairly large number of cosmetic changes by me.
Reviewed and tested by Ashutosh Sharma, Andres Freund, John Naylor,
Greg Nancarrow, Neha Sharma. Additional feedback from Bruce Momjian,
Heikki Linnakangas, Julien Rouhaud, Adam Brusselback, Kyotaro
Horiguchi, Tomas Vondra, Andrew Dunstan, Álvaro Herrera, and others.
Discussion: http://postgr.es/m/CA+TgmoYtcdxBjLh31DLxUXHxFVMPGzrU5_T=CYCvRyFHywSBUQ@mail.gmail.com
2022-03-29 17:31:43 +02:00
|
|
|
/*
|
|
|
|
* Single WAL record for an entire CREATE DATABASE operation. This is used
|
|
|
|
* by the FILE_COPY strategy.
|
|
|
|
*/
|
|
|
|
typedef struct xl_dbase_create_file_copy_rec
|
2015-03-09 14:49:10 +01:00
|
|
|
{
|
|
|
|
Oid db_id;
|
|
|
|
Oid tablespace_id;
|
|
|
|
Oid src_db_id;
|
|
|
|
Oid src_tablespace_id;
|
Add new block-by-block strategy for CREATE DATABASE.
Because this strategy logs changes on a block-by-block basis, it
avoids the need to checkpoint before and after the operation.
However, because it logs each changed block individually, it might
generate a lot of extra write-ahead logging if the template database
is large. Therefore, the older strategy remains available via a new
STRATEGY parameter to CREATE DATABASE, and a corresponding --strategy
option to createdb.
Somewhat controversially, this patch assembles the list of relations
to be copied to the new database by reading the pg_class relation of
the template database. Cross-database access like this isn't normally
possible, but it can be made to work here because there can't be any
connections to the database being copied, nor can it contain any
in-doubt transactions. Even so, we have to use lower-level interfaces
than normal, since the table scan and relcache interfaces will not
work for a database to which we're not connected. The advantage of
this approach is that we do not need to rely on the filesystem to
determine what ought to be copied, but instead on PostgreSQL's own
knowledge of the database structure. This avoids, for example,
copying stray files that happen to be located in the source database
directory.
Dilip Kumar, with a fairly large number of cosmetic changes by me.
Reviewed and tested by Ashutosh Sharma, Andres Freund, John Naylor,
Greg Nancarrow, Neha Sharma. Additional feedback from Bruce Momjian,
Heikki Linnakangas, Julien Rouhaud, Adam Brusselback, Kyotaro
Horiguchi, Tomas Vondra, Andrew Dunstan, Álvaro Herrera, and others.
Discussion: http://postgr.es/m/CA+TgmoYtcdxBjLh31DLxUXHxFVMPGzrU5_T=CYCvRyFHywSBUQ@mail.gmail.com
2022-03-29 17:31:43 +02:00
|
|
|
} xl_dbase_create_file_copy_rec;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* WAL record for the beginning of a CREATE DATABASE operation, when the
|
|
|
|
* WAL_LOG strategy is used. Each individual block will be logged separately
|
|
|
|
* afterward.
|
|
|
|
*/
|
|
|
|
typedef struct xl_dbase_create_wal_log_rec
|
|
|
|
{
|
|
|
|
Oid db_id;
|
|
|
|
Oid tablespace_id;
|
|
|
|
} xl_dbase_create_wal_log_rec;
|
2015-03-09 14:49:10 +01:00
|
|
|
|
|
|
|
typedef struct xl_dbase_drop_rec
|
|
|
|
{
|
|
|
|
Oid db_id;
|
2019-11-21 13:10:37 +01:00
|
|
|
int ntablespaces; /* number of tablespace IDs */
|
|
|
|
Oid tablespace_ids[FLEXIBLE_ARRAY_MEMBER];
|
2015-03-09 14:49:10 +01:00
|
|
|
} xl_dbase_drop_rec;
|
2019-11-21 13:10:37 +01:00
|
|
|
#define MinSizeOfDbaseDropRec offsetof(xl_dbase_drop_rec, tablespace_ids)
|
2015-03-09 14:49:10 +01:00
|
|
|
|
|
|
|
extern void dbase_redo(XLogReaderState *rptr);
|
|
|
|
extern void dbase_desc(StringInfo buf, XLogReaderState *rptr);
|
|
|
|
extern const char *dbase_identify(uint8 info);
|
|
|
|
|
|
|
|
#endif /* DBCOMMANDS_XLOG_H */
|