PostgreSQL Source Code git master
Loading...
Searching...
No Matches
tablespace.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * tablespace.c
4 * Commands to manipulate table spaces
5 *
6 * Tablespaces in PostgreSQL are designed to allow users to determine
7 * where the data file(s) for a given database object reside on the file
8 * system.
9 *
10 * A tablespace represents a directory on the file system. At tablespace
11 * creation time, the directory must be empty. To simplify things and
12 * remove the possibility of having file name conflicts, we isolate
13 * files within a tablespace into database-specific subdirectories.
14 *
15 * To support file access via the information given in RelFileLocator, we
16 * maintain a symbolic-link map in $PGDATA/pg_tblspc. The symlinks are
17 * named by tablespace OIDs and point to the actual tablespace directories.
18 * There is also a per-cluster version directory in each tablespace.
19 * Thus the full path to an arbitrary file is
20 * $PGDATA/pg_tblspc/spcoid/PG_MAJORVER_CATVER/dboid/relfilenumber
21 * e.g.
22 * $PGDATA/pg_tblspc/20981/PG_9.0_201002161/719849/83292814
23 *
24 * There are two tablespaces created at initdb time: pg_global (for shared
25 * tables) and pg_default (for everything else). For backwards compatibility
26 * and to remain functional on platforms without symlinks, these tablespaces
27 * are accessed specially: they are respectively
28 * $PGDATA/global/relfilenumber
29 * $PGDATA/base/dboid/relfilenumber
30 *
31 * To allow CREATE DATABASE to give a new database a default tablespace
32 * that's different from the template database's default, we make the
33 * provision that a zero in pg_class.reltablespace means the database's
34 * default tablespace. Without this, CREATE DATABASE would have to go in
35 * and munge the system catalogs of the new database.
36 *
37 *
38 * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
39 * Portions Copyright (c) 1994, Regents of the University of California
40 *
41 *
42 * IDENTIFICATION
43 * src/backend/commands/tablespace.c
44 *
45 *-------------------------------------------------------------------------
46 */
47#include "postgres.h"
48
49#include <unistd.h>
50#include <dirent.h>
51#include <sys/stat.h>
52
53#include "access/heapam.h"
54#include "access/htup_details.h"
55#include "access/reloptions.h"
56#include "access/tableam.h"
57#include "access/xact.h"
58#include "access/xloginsert.h"
59#include "access/xlogutils.h"
61#include "catalog/catalog.h"
62#include "catalog/dependency.h"
63#include "catalog/indexing.h"
66#include "commands/comment.h"
67#include "commands/seclabel.h"
68#include "commands/tablespace.h"
69#include "common/file_perm.h"
70#include "miscadmin.h"
71#include "postmaster/bgwriter.h"
72#include "storage/fd.h"
73#include "storage/procsignal.h"
74#include "storage/standby.h"
75#include "utils/acl.h"
76#include "utils/builtins.h"
77#include "utils/fmgroids.h"
78#include "utils/guc_hooks.h"
79#include "utils/memutils.h"
80#include "utils/rel.h"
81#include "utils/varlena.h"
82
83/* GUC variables */
87
89
90static void create_tablespace_directories(const char *location,
91 const Oid tablespaceoid);
93
94
95/*
96 * Each database using a table space is isolated into its own name space
97 * by a subdirectory named for the database OID. On first creation of an
98 * object in the tablespace, create the subdirectory. If the subdirectory
99 * already exists, fall through quietly.
100 *
101 * isRedo indicates that we are creating an object during WAL replay.
102 * In this case we will cope with the possibility of the tablespace
103 * directory not being there either --- this could happen if we are
104 * replaying an operation on a table in a subsequently-dropped tablespace.
105 * We handle this by making a directory in the place where the tablespace
106 * symlink would normally be. This isn't an exact replay of course, but
107 * it's the best we can do given the available information.
108 *
109 * If tablespaces are not supported, we still need it in case we have to
110 * re-create a database subdirectory (of $PGDATA/base) during WAL replay.
111 */
112void
114{
115 struct stat st;
116 char *dir;
117
118 /*
119 * The global tablespace doesn't have per-database subdirectories, so
120 * nothing to do for it.
121 */
122 if (spcOid == GLOBALTABLESPACE_OID)
123 return;
124
125 Assert(OidIsValid(spcOid));
126 Assert(OidIsValid(dbOid));
127
128 dir = GetDatabasePath(dbOid, spcOid);
129
130 if (stat(dir, &st) < 0)
131 {
132 /* Directory does not exist? */
133 if (errno == ENOENT)
134 {
135 /*
136 * Acquire TablespaceCreateLock to ensure that no DROP TABLESPACE
137 * or TablespaceCreateDbspace is running concurrently.
138 */
140
141 /*
142 * Recheck to see if someone created the directory while we were
143 * waiting for lock.
144 */
145 if (stat(dir, &st) == 0 && S_ISDIR(st.st_mode))
146 {
147 /* Directory was created */
148 }
149 else
150 {
151 /* Directory creation failed? */
152 if (MakePGDirectory(dir) < 0)
153 {
154 /* Failure other than not exists or not in WAL replay? */
155 if (errno != ENOENT || !isRedo)
158 errmsg("could not create directory \"%s\": %m",
159 dir)));
160
161 /*
162 * During WAL replay, it's conceivable that several levels
163 * of directories are missing if tablespaces are dropped
164 * further ahead of the WAL stream than we're currently
165 * replaying. An easy way forward is to create them as
166 * plain directories and hope they are removed by further
167 * WAL replay if necessary. If this also fails, there is
168 * trouble we cannot get out of, so just report that and
169 * bail out.
170 */
171 if (pg_mkdir_p(dir, pg_dir_create_mode) < 0)
174 errmsg("could not create directory \"%s\": %m",
175 dir)));
176 }
177 }
178
180 }
181 else
182 {
185 errmsg("could not stat directory \"%s\": %m", dir)));
186 }
187 }
188 else
189 {
190 /* Is it not a directory? */
191 if (!S_ISDIR(st.st_mode))
194 errmsg("\"%s\" exists but is not a directory",
195 dir)));
196 }
197
198 pfree(dir);
199}
200
201/*
202 * Create a table space
203 *
204 * Only superusers can create a tablespace. This seems a reasonable restriction
205 * since we're determining the system layout and, anyway, we probably have
206 * root if we're doing this kind of activity
207 */
208Oid
210{
211 Relation rel;
213 bool nulls[Natts_pg_tablespace] = {0};
214 HeapTuple tuple;
216 char *location;
217 Oid ownerId;
219 bool in_place;
220
221 /* Must be superuser */
222 if (!superuser())
225 errmsg("permission denied to create tablespace \"%s\"",
226 stmt->tablespacename),
227 errhint("Must be superuser to create a tablespace.")));
228
229 /* However, the eventual owner of the tablespace need not be */
230 if (stmt->owner)
231 ownerId = get_rolespec_oid(stmt->owner, false);
232 else
233 ownerId = GetUserId();
234
235 /* Unix-ify the offered path, and strip any trailing slashes */
236 location = pstrdup(stmt->location);
237 canonicalize_path(location);
238
239 /* disallow quotes, else CREATE DATABASE would be at risk */
240 if (strchr(location, '\''))
243 errmsg("tablespace location cannot contain single quotes")));
244
245 in_place = allow_in_place_tablespaces && strlen(location) == 0;
246
247 /*
248 * Allowing relative paths seems risky
249 *
250 * This also helps us ensure that location is not empty or whitespace,
251 * unless specifying a developer-only in-place tablespace.
252 */
253 if (!in_place && !is_absolute_path(location))
256 errmsg("tablespace location must be an absolute path")));
257
258 /*
259 * Check that location isn't too long. Remember that we're going to append
260 * 'PG_XXX/<dboid>/<relid>_<fork>.<nnn>'. FYI, we never actually
261 * reference the whole path here, but MakePGDirectory() uses the first two
262 * parts.
263 */
264 if (strlen(location) + 1 + strlen(TABLESPACE_VERSION_DIRECTORY) + 1 +
268 errmsg("tablespace location \"%s\" is too long",
269 location)));
270
271 /* Warn if the tablespace is in the data directory. */
272 if (path_is_prefix_of_path(DataDir, location))
275 errmsg("tablespace location should not be inside the data directory")));
276
277 /*
278 * Disallow creation of tablespaces named "pg_xxx"; we reserve this
279 * namespace for system purposes.
280 */
281 if (!allowSystemTableMods && IsReservedName(stmt->tablespacename))
284 errmsg("unacceptable tablespace name \"%s\"",
285 stmt->tablespacename),
286 errdetail("The prefix \"pg_\" is reserved for system tablespaces.")));
287
288 /*
289 * If built with appropriate switch, whine when regression-testing
290 * conventions for tablespace names are violated.
291 */
292#ifdef ENFORCE_REGRESSION_TEST_NAME_RESTRICTIONS
293 if (strncmp(stmt->tablespacename, "regress_", 8) != 0)
294 elog(WARNING, "tablespaces created by regression test cases should have names starting with \"regress_\"");
295#endif
296
297 /*
298 * Check that there is no other tablespace by this name. (The unique
299 * index would catch this anyway, but might as well give a friendlier
300 * message.)
301 */
302 if (OidIsValid(get_tablespace_oid(stmt->tablespacename, true)))
305 errmsg("tablespace \"%s\" already exists",
306 stmt->tablespacename)));
307
308 /*
309 * Insert tuple into pg_tablespace. The purpose of doing this first is to
310 * lock the proposed tablename against other would-be creators. The
311 * insertion will roll back if we find problems below.
312 */
314
315 if (IsBinaryUpgrade)
316 {
317 /* Use binary-upgrade override for tablespace oid */
321 errmsg("pg_tablespace OID value not set when in binary upgrade mode")));
322
325 }
326 else
333 ObjectIdGetDatum(ownerId);
334 nulls[Anum_pg_tablespace_spcacl - 1] = true;
335
336 /* Generate new proposed spcoptions (text array) */
338 stmt->options,
339 NULL, NULL, false, false);
341 if (newOptions != (Datum) 0)
343 else
344 nulls[Anum_pg_tablespace_spcoptions - 1] = true;
345
346 tuple = heap_form_tuple(rel->rd_att, values, nulls);
347
348 CatalogTupleInsert(rel, tuple);
349
350 heap_freetuple(tuple);
351
352 /* Record dependency on owner */
354
355 /* Post creation hook for new tablespace */
357
359
360 /* Record the filesystem change in XLOG */
361 {
363
365
369 XLogRegisterData(location, strlen(location) + 1);
370
372 }
373
374 /*
375 * Force synchronous commit, to minimize the window between creating the
376 * symlink on-disk and marking the transaction committed. It's not great
377 * that there is any window at all, but definitely we don't want to make
378 * it larger than necessary.
379 */
381
382 pfree(location);
383
384 /* We keep the lock on pg_tablespace until commit */
385 table_close(rel, NoLock);
386
387 return tablespaceoid;
388}
389
390/*
391 * Drop a table space
392 *
393 * Be careful to check that the tablespace is empty.
394 */
395void
397{
398 char *tablespacename = stmt->tablespacename;
399 TableScanDesc scandesc;
400 Relation rel;
401 HeapTuple tuple;
403 ScanKeyData entry[1];
405 char *detail;
406 char *detail_log;
407
408 /*
409 * Find the target tuple
410 */
412
413 ScanKeyInit(&entry[0],
416 CStringGetDatum(tablespacename));
417 scandesc = table_beginscan_catalog(rel, 1, entry);
418 tuple = heap_getnext(scandesc, ForwardScanDirection);
419
420 if (!HeapTupleIsValid(tuple))
421 {
422 if (!stmt->missing_ok)
423 {
426 errmsg("tablespace \"%s\" does not exist",
427 tablespacename)));
428 }
429 else
430 {
432 (errmsg("tablespace \"%s\" does not exist, skipping",
433 tablespacename)));
434 table_endscan(scandesc);
435 table_close(rel, NoLock);
436 }
437 return;
438 }
439
441 tablespaceoid = spcform->oid;
442
443 /* Must be tablespace owner */
446 tablespacename);
447
448 /* Disallow drop of the standard tablespaces, even by superuser */
451 tablespacename);
452
453 /* Check for pg_shdepend entries depending on this tablespace */
455 &detail, &detail_log))
458 errmsg("tablespace \"%s\" cannot be dropped because some objects depend on it",
459 tablespacename),
460 errdetail_internal("%s", detail),
461 errdetail_log("%s", detail_log)));
462
463 /* DROP hook for the tablespace being removed */
465
466 /*
467 * Remove the pg_tablespace tuple (this will roll back if we fail below)
468 */
469 CatalogTupleDelete(rel, &tuple->t_self);
470
471 table_endscan(scandesc);
472
473 /*
474 * Remove any comments or security labels on this tablespace.
475 */
478
479 /*
480 * Remove dependency on owner.
481 */
483
484 /*
485 * Acquire TablespaceCreateLock to ensure that no TablespaceCreateDbspace
486 * is running concurrently.
487 */
489
490 /*
491 * Try to remove the physical infrastructure.
492 */
494 {
495 /*
496 * Not all files deleted? However, there can be lingering empty files
497 * in the directories, left behind by for example DROP TABLE, that
498 * have been scheduled for deletion at next checkpoint (see comments
499 * in mdunlink() for details). We could just delete them immediately,
500 * but we can't tell them apart from important data files that we
501 * mustn't delete. So instead, we force a checkpoint which will clean
502 * out any lingering files, and try again.
503 */
505
506 /*
507 * On Windows, an unlinked file persists in the directory listing
508 * until no process retains an open handle for the file. The DDL
509 * commands that schedule files for unlink send invalidation messages
510 * directing other PostgreSQL processes to close the files, but
511 * nothing guarantees they'll be processed in time. So, we'll also
512 * use a global barrier to ask all backends to close all files, and
513 * wait until they're finished.
514 */
518
519 /* And now try again. */
521 {
522 /* Still not empty, the files must be important then */
525 errmsg("tablespace \"%s\" is not empty",
526 tablespacename)));
527 }
528 }
529
530 /* Record the filesystem change in XLOG */
531 {
533
535
538
540 }
541
542 /*
543 * Note: because we checked that the tablespace was empty, there should be
544 * no need to worry about flushing shared buffers or free space map
545 * entries for relations in the tablespace.
546 */
547
548 /*
549 * Force synchronous commit, to minimize the window between removing the
550 * files on-disk and marking the transaction committed. It's not great
551 * that there is any window at all, but definitely we don't want to make
552 * it larger than necessary.
553 */
555
556 /*
557 * Allow TablespaceCreateDbspace again.
558 */
560
561 /* We keep the lock on pg_tablespace until commit */
562 table_close(rel, NoLock);
563}
564
565
566/*
567 * create_tablespace_directories
568 *
569 * Attempt to create filesystem infrastructure linking $PGDATA/pg_tblspc/
570 * to the specified directory
571 */
572static void
574{
575 char *linkloc;
577 struct stat st;
578 bool in_place;
579
581
582 /*
583 * If we're asked to make an 'in place' tablespace, create the directory
584 * directly where the symlink would normally go. This is a developer-only
585 * option for now, to facilitate regression testing.
586 */
587 in_place = strlen(location) == 0;
588
589 if (in_place)
590 {
591 if (MakePGDirectory(linkloc) < 0 && errno != EEXIST)
594 errmsg("could not create directory \"%s\": %m",
595 linkloc)));
596 }
597
598 location_with_version_dir = psprintf("%s/%s", in_place ? linkloc : location,
600
601 /*
602 * Attempt to coerce target directory to safe permissions. If this fails,
603 * it doesn't exist or has the wrong owner. Not needed for in-place mode,
604 * because in that case we created the directory with the desired
605 * permissions.
606 */
607 if (!in_place && chmod(location, pg_dir_create_mode) != 0)
608 {
609 if (errno == ENOENT)
612 errmsg("directory \"%s\" does not exist", location),
613 InRecovery ? errhint("Create this directory for the tablespace before "
614 "restarting the server.") : 0));
615 else
618 errmsg("could not set permissions on directory \"%s\": %m",
619 location)));
620 }
621
622 /*
623 * The creation of the version directory prevents more than one tablespace
624 * in a single location. This imitates TablespaceCreateDbspace(), but it
625 * ignores concurrency and missing parent directories. The chmod() would
626 * have failed in the absence of a parent. pg_tablespace_spcname_index
627 * prevents concurrency.
628 */
629 if (stat(location_with_version_dir, &st) < 0)
630 {
631 if (errno != ENOENT)
634 errmsg("could not stat directory \"%s\": %m",
639 errmsg("could not create directory \"%s\": %m",
641 }
642 else if (!S_ISDIR(st.st_mode))
645 errmsg("\"%s\" exists but is not a directory",
647 else if (!InRecovery)
650 errmsg("directory \"%s\" already in use as a tablespace",
652
653 /*
654 * In recovery, remove old symlink, in case it points to the wrong place.
655 */
656 if (!in_place && InRecovery)
658
659 /*
660 * Create the symlink under PGDATA
661 */
662 if (!in_place && symlink(location, linkloc) < 0)
665 errmsg("could not create symbolic link \"%s\": %m",
666 linkloc)));
667
668 pfree(linkloc);
670}
671
672
673/*
674 * destroy_tablespace_directories
675 *
676 * Attempt to remove filesystem infrastructure for the tablespace.
677 *
678 * 'redo' indicates we are redoing a drop from XLOG; in that case we should
679 * not throw an ERROR for problems, just LOG them. The worst consequence of
680 * not removing files here would be failure to release some disk space, which
681 * does not justify throwing an error that would require manual intervention
682 * to get the database running again.
683 *
684 * Returns true if successful, false if some subdirectory is not empty
685 */
686static bool
688{
689 char *linkloc;
691 DIR *dirdesc;
692 struct dirent *de;
693 char *subfile;
694 struct stat st;
695
698
699 /*
700 * Check if the tablespace still contains any files. We try to rmdir each
701 * per-database directory we find in it. rmdir failure implies there are
702 * still files in that subdirectory, so give up. (We do not have to worry
703 * about undoing any already completed rmdirs, since the next attempt to
704 * use the tablespace from that database will simply recreate the
705 * subdirectory via TablespaceCreateDbspace.)
706 *
707 * Since we hold TablespaceCreateLock, no one else should be creating any
708 * fresh subdirectories in parallel. It is possible that new files are
709 * being created within subdirectories, though, so the rmdir call could
710 * fail. Worst consequence is a less friendly error message.
711 *
712 * If redo is true then ENOENT is a likely outcome here, and we allow it
713 * to pass without comment. In normal operation we still allow it, but
714 * with a warning. This is because even though ProcessUtility disallows
715 * DROP TABLESPACE in a transaction block, it's possible that a previous
716 * DROP failed and rolled back after removing the tablespace directories
717 * and/or symlink. We want to allow a new DROP attempt to succeed at
718 * removing the catalog entries (and symlink if still present), so we
719 * should not give a hard error here.
720 */
722 if (dirdesc == NULL)
723 {
724 if (errno == ENOENT)
725 {
726 if (!redo)
729 errmsg("could not open directory \"%s\": %m",
731 /* The symlink might still exist, so go try to remove it */
732 goto remove_symlink;
733 }
734 else if (redo)
735 {
736 /* in redo, just log other types of error */
737 ereport(LOG,
739 errmsg("could not open directory \"%s\": %m",
742 return false;
743 }
744 /* else let ReadDir report the error */
745 }
746
747 while ((de = ReadDir(dirdesc, linkloc_with_version_dir)) != NULL)
748 {
749 if (strcmp(de->d_name, ".") == 0 ||
750 strcmp(de->d_name, "..") == 0)
751 continue;
752
753 subfile = psprintf("%s/%s", linkloc_with_version_dir, de->d_name);
754
755 /* This check is just to deliver a friendlier error message */
756 if (!redo && !directory_is_empty(subfile))
757 {
758 FreeDir(dirdesc);
759 pfree(subfile);
761 return false;
762 }
763
764 /* remove empty directory */
765 if (rmdir(subfile) < 0)
766 ereport(redo ? LOG : ERROR,
768 errmsg("could not remove directory \"%s\": %m",
769 subfile)));
770
771 pfree(subfile);
772 }
773
774 FreeDir(dirdesc);
775
776 /* remove version directory */
778 {
779 ereport(redo ? LOG : ERROR,
781 errmsg("could not remove directory \"%s\": %m",
784 return false;
785 }
786
787 /*
788 * Try to remove the symlink. We must however deal with the possibility
789 * that it's a directory instead of a symlink --- this could happen during
790 * WAL replay (see TablespaceCreateDbspace).
791 *
792 * Note: in the redo case, we'll return true if this final step fails;
793 * there's no point in retrying it. Also, ENOENT should provoke no more
794 * than a warning.
795 */
799 if (lstat(linkloc, &st) < 0)
800 {
801 int saved_errno = errno;
802
803 ereport(redo ? LOG : (saved_errno == ENOENT ? WARNING : ERROR),
805 errmsg("could not stat file \"%s\": %m",
806 linkloc)));
807 }
808 else if (S_ISDIR(st.st_mode))
809 {
810 if (rmdir(linkloc) < 0)
811 {
812 int saved_errno = errno;
813
814 ereport(redo ? LOG : (saved_errno == ENOENT ? WARNING : ERROR),
816 errmsg("could not remove directory \"%s\": %m",
817 linkloc)));
818 }
819 }
820 else if (S_ISLNK(st.st_mode))
821 {
822 if (unlink(linkloc) < 0)
823 {
824 int saved_errno = errno;
825
826 ereport(redo ? LOG : (saved_errno == ENOENT ? WARNING : ERROR),
828 errmsg("could not remove symbolic link \"%s\": %m",
829 linkloc)));
830 }
831 }
832 else
833 {
834 /* Refuse to remove anything that's not a directory or symlink */
835 ereport(redo ? LOG : ERROR,
837 errmsg("\"%s\" is not a directory or symbolic link",
838 linkloc)));
839 }
840
842 pfree(linkloc);
843
844 return true;
845}
846
847
848/*
849 * Check if a directory is empty.
850 *
851 * This probably belongs somewhere else, but not sure where...
852 */
853bool
854directory_is_empty(const char *path)
855{
856 DIR *dirdesc;
857 struct dirent *de;
858
859 dirdesc = AllocateDir(path);
860
861 while ((de = ReadDir(dirdesc, path)) != NULL)
862 {
863 if (strcmp(de->d_name, ".") == 0 ||
864 strcmp(de->d_name, "..") == 0)
865 continue;
866 FreeDir(dirdesc);
867 return false;
868 }
869
870 FreeDir(dirdesc);
871 return true;
872}
873
874/*
875 * remove_tablespace_symlink
876 *
877 * This function removes symlinks in pg_tblspc. On Windows, junction points
878 * act like directories so we must be able to apply rmdir. This function
879 * works like the symlink removal code in destroy_tablespace_directories,
880 * except that failure to remove is always an ERROR. But if the file doesn't
881 * exist at all, that's OK.
882 */
883void
885{
886 struct stat st;
887
888 if (lstat(linkloc, &st) < 0)
889 {
890 if (errno == ENOENT)
891 return;
894 errmsg("could not stat file \"%s\": %m", linkloc)));
895 }
896
897 if (S_ISDIR(st.st_mode))
898 {
899 /*
900 * This will fail if the directory isn't empty, but not if it's a
901 * junction point.
902 */
903 if (rmdir(linkloc) < 0 && errno != ENOENT)
906 errmsg("could not remove directory \"%s\": %m",
907 linkloc)));
908 }
909 else if (S_ISLNK(st.st_mode))
910 {
911 if (unlink(linkloc) < 0 && errno != ENOENT)
914 errmsg("could not remove symbolic link \"%s\": %m",
915 linkloc)));
916 }
917 else
918 {
919 /* Refuse to remove anything that's not a directory or symlink */
922 errmsg("\"%s\" is not a directory or symbolic link",
923 linkloc)));
924 }
925}
926
927/*
928 * Rename a tablespace
929 */
931RenameTableSpace(const char *oldname, const char *newname)
932{
933 Oid tspId;
934 Relation rel;
935 ScanKeyData entry[1];
936 TableScanDesc scan;
938 HeapTuple newtuple;
940 ObjectAddress address;
941
942 /* Search pg_tablespace */
944
945 ScanKeyInit(&entry[0],
949 scan = table_beginscan_catalog(rel, 1, entry);
951 if (!HeapTupleIsValid(tup))
954 errmsg("tablespace \"%s\" does not exist",
955 oldname)));
956
957 newtuple = heap_copytuple(tup);
959 tspId = newform->oid;
960
961 table_endscan(scan);
962
963 /* Must be owner */
966
967 /* Validate new name */
968 if (!allowSystemTableMods && IsReservedName(newname))
971 errmsg("unacceptable tablespace name \"%s\"", newname),
972 errdetail("The prefix \"pg_\" is reserved for system tablespaces.")));
973
974 /*
975 * If built with appropriate switch, whine when regression-testing
976 * conventions for tablespace names are violated.
977 */
978#ifdef ENFORCE_REGRESSION_TEST_NAME_RESTRICTIONS
979 if (strncmp(newname, "regress_", 8) != 0)
980 elog(WARNING, "tablespaces created by regression test cases should have names starting with \"regress_\"");
981#endif
982
983 /* Make sure the new name doesn't exist */
984 ScanKeyInit(&entry[0],
987 CStringGetDatum(newname));
988 scan = table_beginscan_catalog(rel, 1, entry);
993 errmsg("tablespace \"%s\" already exists",
994 newname)));
995
996 table_endscan(scan);
997
998 /* OK, update the entry */
999 namestrcpy(&(newform->spcname), newname);
1000
1001 CatalogTupleUpdate(rel, &newtuple->t_self, newtuple);
1002
1004
1006
1007 table_close(rel, NoLock);
1008
1009 return address;
1010}
1011
1012/*
1013 * Alter table space options
1014 */
1015Oid
1017{
1018 Relation rel;
1019 ScanKeyData entry[1];
1020 TableScanDesc scandesc;
1021 HeapTuple tup;
1023 Datum datum;
1026 bool isnull;
1029 HeapTuple newtuple;
1030
1031 /* Search pg_tablespace */
1033
1034 ScanKeyInit(&entry[0],
1037 CStringGetDatum(stmt->tablespacename));
1038 scandesc = table_beginscan_catalog(rel, 1, entry);
1040 if (!HeapTupleIsValid(tup))
1041 ereport(ERROR,
1043 errmsg("tablespace \"%s\" does not exist",
1044 stmt->tablespacename)));
1045
1047
1048 /* Must be owner of the existing object */
1051 stmt->tablespacename);
1052
1053 /* Generate new proposed spcoptions (text array) */
1055 RelationGetDescr(rel), &isnull);
1056 newOptions = transformRelOptions(isnull ? (Datum) 0 : datum,
1057 stmt->options, NULL, NULL, false,
1058 stmt->isReset);
1060
1061 /* Build new tuple. */
1062 memset(repl_null, false, sizeof(repl_null));
1063 memset(repl_repl, false, sizeof(repl_repl));
1064 if (newOptions != (Datum) 0)
1066 else
1071
1072 /* Update system catalog. */
1073 CatalogTupleUpdate(rel, &newtuple->t_self, newtuple);
1074
1076
1077 heap_freetuple(newtuple);
1078
1079 /* Conclude heap scan. */
1080 table_endscan(scandesc);
1081 table_close(rel, NoLock);
1082
1083 return tablespaceoid;
1084}
1085
1086/*
1087 * Routines for handling the GUC variable 'default_tablespace'.
1088 */
1089
1090/* check_hook: validate new default_tablespace */
1091bool
1093{
1094 /*
1095 * If we aren't inside a transaction, or connected to a database, we
1096 * cannot do the catalog accesses necessary to verify the name. Must
1097 * accept the value on faith.
1098 */
1100 {
1101 if (**newval != '\0' &&
1103 {
1104 /*
1105 * When source == PGC_S_TEST, don't throw a hard error for a
1106 * nonexistent tablespace, only a NOTICE. See comments in guc.h.
1107 */
1108 if (source == PGC_S_TEST)
1109 {
1112 errmsg("tablespace \"%s\" does not exist",
1113 *newval)));
1114 }
1115 else
1116 {
1117 GUC_check_errdetail("Tablespace \"%s\" does not exist.",
1118 *newval);
1119 return false;
1120 }
1121 }
1122 }
1123
1124 return true;
1125}
1126
1127/*
1128 * GetDefaultTablespace -- get the OID of the current default tablespace
1129 *
1130 * Temporary objects have different default tablespaces, hence the
1131 * relpersistence parameter must be specified. Also, for partitioned tables,
1132 * we disallow specifying the database default, so that needs to be specified
1133 * too.
1134 *
1135 * May return InvalidOid to indicate "use the database's default tablespace".
1136 *
1137 * Note that caller is expected to check appropriate permissions for any
1138 * result other than InvalidOid.
1139 *
1140 * This exists to hide (and possibly optimize the use of) the
1141 * default_tablespace GUC variable.
1142 */
1143Oid
1144GetDefaultTablespace(char relpersistence, bool partitioned)
1145{
1146 Oid result;
1147
1148 /* The temp-table case is handled elsewhere */
1149 if (relpersistence == RELPERSISTENCE_TEMP)
1150 {
1152 return GetNextTempTableSpace();
1153 }
1154
1155 /* Fast path for default_tablespace == "" */
1156 if (default_tablespace == NULL || default_tablespace[0] == '\0')
1157 return InvalidOid;
1158
1159 /*
1160 * It is tempting to cache this lookup for more speed, but then we would
1161 * fail to detect the case where the tablespace was dropped since the GUC
1162 * variable was set. Note also that we don't complain if the value fails
1163 * to refer to an existing tablespace; we just silently return InvalidOid,
1164 * causing the new object to be created in the database's tablespace.
1165 */
1166 result = get_tablespace_oid(default_tablespace, true);
1167
1168 /*
1169 * Allow explicit specification of database's default tablespace in
1170 * default_tablespace without triggering permissions checks. Don't allow
1171 * specifying that when creating a partitioned table, however, since the
1172 * result is confusing.
1173 */
1174 if (result == MyDatabaseTableSpace)
1175 {
1176 if (partitioned)
1177 ereport(ERROR,
1179 errmsg("cannot specify default tablespace for partitioned relations")));
1180 result = InvalidOid;
1181 }
1182 return result;
1183}
1184
1185
1186/*
1187 * Routines for handling the GUC variable 'temp_tablespaces'.
1188 */
1189
1190typedef struct
1191{
1192 /* Array of OIDs to be passed to SetTempTablespaces() */
1196
1197/* check_hook: validate new temp_tablespaces */
1198bool
1200{
1201 char *rawname;
1202 List *namelist;
1203
1204 /* Need a modifiable copy of string */
1206
1207 /* Parse string into list of identifiers */
1209 {
1210 /* syntax error in name list */
1211 GUC_check_errdetail("List syntax is invalid.");
1212 pfree(rawname);
1214 return false;
1215 }
1216
1217 /*
1218 * If we aren't inside a transaction, or connected to a database, we
1219 * cannot do the catalog accesses necessary to verify the name. Must
1220 * accept the value on faith. Fortunately, there's then also no need to
1221 * pass the data to fd.c.
1222 */
1224 {
1226 Oid *tblSpcs;
1227 int numSpcs;
1228 ListCell *l;
1229
1230 /* temporary workspace until we are done verifying the list */
1231 tblSpcs = (Oid *) palloc(list_length(namelist) * sizeof(Oid));
1232 numSpcs = 0;
1233 foreach(l, namelist)
1234 {
1235 char *curname = (char *) lfirst(l);
1236 Oid curoid;
1238
1239 /* Allow an empty string (signifying database default) */
1240 if (curname[0] == '\0')
1241 {
1242 /* InvalidOid signifies database's default tablespace */
1243 tblSpcs[numSpcs++] = InvalidOid;
1244 continue;
1245 }
1246
1247 /*
1248 * In an interactive SET command, we ereport for bad info. When
1249 * source == PGC_S_TEST, don't throw a hard error for a
1250 * nonexistent tablespace, only a NOTICE. See comments in guc.h.
1251 */
1253 if (curoid == InvalidOid)
1254 {
1255 if (source == PGC_S_TEST)
1258 errmsg("tablespace \"%s\" does not exist",
1259 curname)));
1260 continue;
1261 }
1262
1263 /*
1264 * Allow explicit specification of database's default tablespace
1265 * in temp_tablespaces without triggering permissions checks.
1266 */
1268 {
1269 /* InvalidOid signifies database's default tablespace */
1270 tblSpcs[numSpcs++] = InvalidOid;
1271 continue;
1272 }
1273
1274 /* Check permissions, similarly complaining only if interactive */
1276 ACL_CREATE);
1277 if (aclresult != ACLCHECK_OK)
1278 {
1281 continue;
1282 }
1283
1284 tblSpcs[numSpcs++] = curoid;
1285 }
1286
1287 /* Now prepare an "extra" struct for assign_temp_tablespaces */
1289 numSpcs * sizeof(Oid));
1290 if (!myextra)
1291 return false;
1292 myextra->numSpcs = numSpcs;
1293 memcpy(myextra->tblSpcs, tblSpcs, numSpcs * sizeof(Oid));
1294 *extra = myextra;
1295
1296 pfree(tblSpcs);
1297 }
1298
1299 pfree(rawname);
1301
1302 return true;
1303}
1304
1305/* assign_hook: do extra actions as needed */
1306void
1307assign_temp_tablespaces(const char *newval, void *extra)
1308{
1310
1311 /*
1312 * If check_temp_tablespaces was executed inside a transaction, then pass
1313 * the list it made to fd.c. Otherwise, clear fd.c's list; we must be
1314 * still outside a transaction, or else restoring during transaction exit,
1315 * and in either case we can just let the next PrepareTempTablespaces call
1316 * make things sane.
1317 */
1318 if (myextra)
1319 SetTempTablespaces(myextra->tblSpcs, myextra->numSpcs);
1320 else
1322}
1323
1324/*
1325 * PrepareTempTablespaces -- prepare to use temp tablespaces
1326 *
1327 * If we have not already done so in the current transaction, parse the
1328 * temp_tablespaces GUC variable and tell fd.c which tablespace(s) to use
1329 * for temp files.
1330 */
1331void
1333{
1334 char *rawname;
1335 List *namelist;
1336 Oid *tblSpcs;
1337 int numSpcs;
1338 ListCell *l;
1339
1340 /* No work if already done in current transaction */
1342 return;
1343
1344 /*
1345 * Can't do catalog access unless within a transaction. This is just a
1346 * safety check in case this function is called by low-level code that
1347 * could conceivably execute outside a transaction. Note that in such a
1348 * scenario, fd.c will fall back to using the current database's default
1349 * tablespace, which should always be OK.
1350 */
1351 if (!IsTransactionState())
1352 return;
1353
1354 /* Need a modifiable copy of string */
1356
1357 /* Parse string into list of identifiers */
1359 {
1360 /* syntax error in name list */
1362 pfree(rawname);
1364 return;
1365 }
1366
1367 /* Store tablespace OIDs in an array in TopTransactionContext */
1369 list_length(namelist) * sizeof(Oid));
1370 numSpcs = 0;
1371 foreach(l, namelist)
1372 {
1373 char *curname = (char *) lfirst(l);
1374 Oid curoid;
1376
1377 /* Allow an empty string (signifying database default) */
1378 if (curname[0] == '\0')
1379 {
1380 /* InvalidOid signifies database's default tablespace */
1381 tblSpcs[numSpcs++] = InvalidOid;
1382 continue;
1383 }
1384
1385 /* Else verify that name is a valid tablespace name */
1387 if (curoid == InvalidOid)
1388 {
1389 /* Skip any bad list elements */
1390 continue;
1391 }
1392
1393 /*
1394 * Allow explicit specification of database's default tablespace in
1395 * temp_tablespaces without triggering permissions checks.
1396 */
1398 {
1399 /* InvalidOid signifies database's default tablespace */
1400 tblSpcs[numSpcs++] = InvalidOid;
1401 continue;
1402 }
1403
1404 /* Check permissions similarly */
1406 ACL_CREATE);
1407 if (aclresult != ACLCHECK_OK)
1408 continue;
1409
1410 tblSpcs[numSpcs++] = curoid;
1411 }
1412
1413 SetTempTablespaces(tblSpcs, numSpcs);
1414
1415 pfree(rawname);
1417}
1418
1419
1420/*
1421 * get_tablespace_oid - given a tablespace name, look up the OID
1422 *
1423 * If missing_ok is false, throw an error if tablespace name not found. If
1424 * true, just return InvalidOid.
1425 */
1426Oid
1427get_tablespace_oid(const char *tablespacename, bool missing_ok)
1428{
1429 Oid result;
1430 Relation rel;
1431 TableScanDesc scandesc;
1432 HeapTuple tuple;
1433 ScanKeyData entry[1];
1434
1435 /*
1436 * Search pg_tablespace. We use a heapscan here even though there is an
1437 * index on name, on the theory that pg_tablespace will usually have just
1438 * a few entries and so an indexed lookup is a waste of effort.
1439 */
1441
1442 ScanKeyInit(&entry[0],
1445 CStringGetDatum(tablespacename));
1446 scandesc = table_beginscan_catalog(rel, 1, entry);
1447 tuple = heap_getnext(scandesc, ForwardScanDirection);
1448
1449 /* We assume that there can be at most one matching tuple */
1450 if (HeapTupleIsValid(tuple))
1451 result = ((Form_pg_tablespace) GETSTRUCT(tuple))->oid;
1452 else
1453 result = InvalidOid;
1454
1455 table_endscan(scandesc);
1457
1458 if (!OidIsValid(result) && !missing_ok)
1459 ereport(ERROR,
1461 errmsg("tablespace \"%s\" does not exist",
1462 tablespacename)));
1463
1464 return result;
1465}
1466
1467/*
1468 * get_tablespace_name - given a tablespace OID, look up the name
1469 *
1470 * Returns a palloc'd string, or NULL if no such tablespace.
1471 */
1472char *
1474{
1475 char *result;
1476 Relation rel;
1477 TableScanDesc scandesc;
1478 HeapTuple tuple;
1479 ScanKeyData entry[1];
1480
1481 /*
1482 * Search pg_tablespace. We use a heapscan here even though there is an
1483 * index on oid, on the theory that pg_tablespace will usually have just a
1484 * few entries and so an indexed lookup is a waste of effort.
1485 */
1487
1488 ScanKeyInit(&entry[0],
1492 scandesc = table_beginscan_catalog(rel, 1, entry);
1493 tuple = heap_getnext(scandesc, ForwardScanDirection);
1494
1495 /* We assume that there can be at most one matching tuple */
1496 if (HeapTupleIsValid(tuple))
1497 result = pstrdup(NameStr(((Form_pg_tablespace) GETSTRUCT(tuple))->spcname));
1498 else
1499 result = NULL;
1500
1501 table_endscan(scandesc);
1503
1504 return result;
1505}
1506
1507
1508/*
1509 * TABLESPACE resource manager's routines
1510 */
1511void
1513{
1514 uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
1515
1516 /* Backup blocks are not used in tblspc records */
1518
1519 if (info == XLOG_TBLSPC_CREATE)
1520 {
1522 char *location = xlrec->ts_path;
1523
1524 create_tablespace_directories(location, xlrec->ts_id);
1525 }
1526 else if (info == XLOG_TBLSPC_DROP)
1527 {
1529
1530 /* Close all smgr fds in all backends. */
1532
1533 /*
1534 * If we issued a WAL record for a drop tablespace it implies that
1535 * there were no files in it at all when the DROP was done. That means
1536 * that no permanent objects can exist in it at this point.
1537 *
1538 * It is possible for standby users to be using this tablespace as a
1539 * location for their temporary files, so if we fail to remove all
1540 * files then do conflict processing and try again, if currently
1541 * enabled.
1542 *
1543 * Other possible reasons for failure include bollixed file
1544 * permissions on a standby server when they were okay on the primary,
1545 * etc etc. There's not much we can do about that, so just remove what
1546 * we can and press on.
1547 */
1548 if (!destroy_tablespace_directories(xlrec->ts_id, true))
1549 {
1551
1552 /*
1553 * If we did recovery processing then hopefully the backends who
1554 * wrote temp files should have cleaned up and exited by now. So
1555 * retry before complaining. If we fail again, this is just a LOG
1556 * condition, because it's not worth throwing an ERROR for (as
1557 * that would crash the database and require manual intervention
1558 * before we could get past this WAL record on restart).
1559 */
1560 if (!destroy_tablespace_directories(xlrec->ts_id, true))
1561 ereport(LOG,
1563 errmsg("directories for tablespace %u could not be removed",
1564 xlrec->ts_id),
1565 errhint("You can remove the directories manually if necessary.")));
1566 }
1567 }
1568 else
1569 elog(PANIC, "tblspc_redo: unknown op code %u", info);
1570}
Oid get_rolespec_oid(const RoleSpec *role, bool missing_ok)
Definition acl.c:5588
AclResult
Definition acl.h:182
@ ACLCHECK_NO_PRIV
Definition acl.h:184
@ ACLCHECK_OK
Definition acl.h:183
@ ACLCHECK_NOT_OWNER
Definition acl.h:185
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition aclchk.c:2654
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
Definition aclchk.c:3836
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
Definition aclchk.c:4090
Oid AlterTableSpaceOptions(AlterTableSpaceOptionsStmt *stmt)
Oid binary_upgrade_next_pg_tablespace_oid
Definition tablespace.c:88
bool directory_is_empty(const char *path)
Definition tablespace.c:854
void remove_tablespace_symlink(const char *linkloc)
Definition tablespace.c:884
static bool destroy_tablespace_directories(Oid tablespaceoid, bool redo)
Definition tablespace.c:687
bool check_default_tablespace(char **newval, void **extra, GucSource source)
char * get_tablespace_name(Oid spc_oid)
void DropTableSpace(DropTableSpaceStmt *stmt)
Definition tablespace.c:396
void PrepareTempTablespaces(void)
Oid get_tablespace_oid(const char *tablespacename, bool missing_ok)
ObjectAddress RenameTableSpace(const char *oldname, const char *newname)
Definition tablespace.c:931
char * temp_tablespaces
Definition tablespace.c:85
void assign_temp_tablespaces(const char *newval, void *extra)
Oid GetDefaultTablespace(char relpersistence, bool partitioned)
void TablespaceCreateDbspace(Oid spcOid, Oid dbOid, bool isRedo)
Definition tablespace.c:113
bool check_temp_tablespaces(char **newval, void **extra, GucSource source)
Oid CreateTableSpace(CreateTableSpaceStmt *stmt)
Definition tablespace.c:209
char * default_tablespace
Definition tablespace.c:84
static void create_tablespace_directories(const char *location, const Oid tablespaceoid)
Definition tablespace.c:573
void tblspc_redo(XLogReaderState *record)
bool allow_in_place_tablespaces
Definition tablespace.c:86
static Datum values[MAXATTR]
Definition bootstrap.c:147
#define NameStr(name)
Definition c.h:777
uint8_t uint8
Definition c.h:556
#define Assert(condition)
Definition c.h:885
#define FLEXIBLE_ARRAY_MEMBER
Definition c.h:492
#define OidIsValid(objectId)
Definition c.h:800
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
Definition catalog.c:448
bool IsPinnedObject(Oid classId, Oid objectId)
Definition catalog.c:370
bool IsReservedName(const char *name)
Definition catalog.c:278
void RequestCheckpoint(int flags)
void DeleteSharedComments(Oid oid, Oid classoid)
Definition comment.c:384
int errdetail_internal(const char *fmt,...)
Definition elog.c:1244
int errcode_for_file_access(void)
Definition elog.c:887
int errdetail(const char *fmt,...)
Definition elog.c:1217
int errhint(const char *fmt,...)
Definition elog.c:1331
int errcode(int sqlerrcode)
Definition elog.c:864
int errmsg(const char *fmt,...)
Definition elog.c:1081
int errdetail_log(const char *fmt,...)
Definition elog.c:1265
#define LOG
Definition elog.h:31
#define WARNING
Definition elog.h:36
#define PANIC
Definition elog.h:42
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
#define NOTICE
Definition elog.h:35
#define ereport(elevel,...)
Definition elog.h:150
int MakePGDirectory(const char *directoryName)
Definition fd.c:3962
int FreeDir(DIR *dir)
Definition fd.c:3008
bool TempTablespacesAreSet(void)
Definition fd.c:3125
Oid GetNextTempTableSpace(void)
Definition fd.c:3158
DIR * AllocateDir(const char *dirname)
Definition fd.c:2890
struct dirent * ReadDir(DIR *dir, const char *dirname)
Definition fd.c:2956
void SetTempTablespaces(Oid *tableSpaces, int numSpaces)
Definition fd.c:3096
int pg_dir_create_mode
Definition file_perm.c:18
#define DirectFunctionCall1(func, arg1)
Definition fmgr.h:684
bool IsBinaryUpgrade
Definition globals.c:121
bool allowSystemTableMods
Definition globals.c:130
Oid MyDatabaseTableSpace
Definition globals.c:96
char * DataDir
Definition globals.c:71
Oid MyDatabaseId
Definition globals.c:94
void * guc_malloc(int elevel, size_t size)
Definition guc.c:636
#define newval
#define GUC_check_errdetail
Definition guc.h:506
GucSource
Definition guc.h:112
@ PGC_S_TEST
Definition guc.h:125
@ PGC_S_INTERACTIVE
Definition guc.h:124
HeapTuple heap_getnext(TableScanDesc sscan, ScanDirection direction)
Definition heapam.c:1409
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, const Datum *replValues, const bool *replIsnull, const bool *doReplace)
Definition heaptuple.c:1210
HeapTuple heap_copytuple(HeapTuple tuple)
Definition heaptuple.c:778
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition heaptuple.c:1117
void heap_freetuple(HeapTuple htup)
Definition heaptuple.c:1435
#define HeapTupleIsValid(tuple)
Definition htup.h:78
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
static void * GETSTRUCT(const HeapTupleData *tuple)
#define stmt
void CatalogTupleUpdate(Relation heapRel, const ItemPointerData *otid, HeapTuple tup)
Definition indexing.c:313
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Definition indexing.c:233
void CatalogTupleDelete(Relation heapRel, const ItemPointerData *tid)
Definition indexing.c:365
void list_free(List *list)
Definition list.c:1546
#define NoLock
Definition lockdefs.h:34
#define AccessShareLock
Definition lockdefs.h:36
#define RowExclusiveLock
Definition lockdefs.h:38
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition lwlock.c:1176
void LWLockRelease(LWLock *lock)
Definition lwlock.c:1793
@ LW_EXCLUSIVE
Definition lwlock.h:112
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition mcxt.c:1232
MemoryContext TopTransactionContext
Definition mcxt.c:171
char * pstrdup(const char *in)
Definition mcxt.c:1781
void pfree(void *pointer)
Definition mcxt.c:1616
void * palloc(Size size)
Definition mcxt.c:1387
Oid GetUserId(void)
Definition miscinit.c:469
void namestrcpy(Name name, const char *str)
Definition name.c:233
Datum namein(PG_FUNCTION_ARGS)
Definition name.c:48
#define InvokeObjectPostCreateHook(classId, objectId, subId)
#define InvokeObjectPostAlterHook(classId, objectId, subId)
#define InvokeObjectDropHook(classId, objectId, subId)
#define ObjectAddressSet(addr, class_id, object_id)
@ OBJECT_TABLESPACE
#define ACL_CREATE
Definition parsenodes.h:85
#define MAXPGPATH
#define lfirst(lc)
Definition pg_list.h:172
static int list_length(const List *l)
Definition pg_list.h:152
static rewind_source * source
Definition pg_rewind.c:89
void deleteSharedDependencyRecordsFor(Oid classId, Oid objectId, int32 objectSubId)
void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner)
bool checkSharedDependencies(Oid classId, Oid objectId, char **detail_msg, char **detail_log_msg)
FormData_pg_tablespace * Form_pg_tablespace
int pg_mkdir_p(char *path, int omode)
Definition pgmkdirp.c:57
#define is_absolute_path(filename)
Definition port.h:104
bool path_is_prefix_of_path(const char *path1, const char *path2)
Definition path.c:637
void canonicalize_path(char *path)
Definition path.c:337
void get_parent_directory(char *path)
Definition path.c:1068
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:262
uint64_t Datum
Definition postgres.h:70
static Datum CStringGetDatum(const char *X)
Definition postgres.h:380
#define InvalidOid
unsigned int Oid
static int fb(int x)
void WaitForProcSignalBarrier(uint64 generation)
Definition procsignal.c:424
uint64 EmitProcSignalBarrier(ProcSignalBarrierType type)
Definition procsignal.c:356
@ PROCSIGNAL_BARRIER_SMGRRELEASE
Definition procsignal.h:48
char * psprintf(const char *fmt,...)
Definition psprintf.c:43
#define RelationGetDescr(relation)
Definition rel.h:540
bytea * tablespace_reloptions(Datum reloptions, bool validate)
Datum transformRelOptions(Datum oldOptions, List *defList, const char *nameSpace, const char *const validnsps[], bool acceptOidsOff, bool isReset)
char * GetDatabasePath(Oid dbOid, Oid spcOid)
Definition relpath.c:110
#define OIDCHARS
Definition relpath.h:45
#define PG_TBLSPC_DIR
Definition relpath.h:41
#define FORKNAMECHARS
Definition relpath.h:72
#define TABLESPACE_VERSION_DIRECTORY
Definition relpath.h:33
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition scankey.c:76
@ ForwardScanDirection
Definition sdir.h:28
void DeleteSharedSecurityLabel(Oid objectId, Oid classId)
Definition seclabel.c:501
void ResolveRecoveryConflictWithTablespace(Oid tsid)
Definition standby.c:540
#define BTEqualStrategyNumber
Definition stratnum.h:31
#define ERRCODE_DUPLICATE_OBJECT
Definition streamutil.c:30
Definition dirent.c:26
ItemPointerData t_self
Definition htup.h:65
Definition pg_list.h:54
TupleDesc rd_att
Definition rel.h:112
unsigned short st_mode
Definition win32_port.h:258
char ts_path[FLEXIBLE_ARRAY_MEMBER]
Definition tablespace.h:33
bool superuser(void)
Definition superuser.c:47
void table_close(Relation relation, LOCKMODE lockmode)
Definition table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition table.c:40
TableScanDesc table_beginscan_catalog(Relation relation, int nkeys, ScanKeyData *key)
Definition tableam.c:113
static void table_endscan(TableScanDesc scan)
Definition tableam.h:1005
#define XLOG_TBLSPC_DROP
Definition tablespace.h:28
#define XLOG_TBLSPC_CREATE
Definition tablespace.h:27
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition varlena.c:2775
#define stat
Definition win32_port.h:74
#define lstat(path, sb)
Definition win32_port.h:275
#define S_ISDIR(m)
Definition win32_port.h:315
#define S_ISLNK(m)
Definition win32_port.h:334
#define symlink(oldpath, newpath)
Definition win32_port.h:225
bool IsTransactionState(void)
Definition xact.c:388
void ForceSyncCommit(void)
Definition xact.c:1153
#define CHECKPOINT_FORCE
Definition xlog.h:153
#define CHECKPOINT_WAIT
Definition xlog.h:156
#define CHECKPOINT_FAST
Definition xlog.h:152
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition xloginsert.c:478
void XLogRegisterData(const void *data, uint32 len)
Definition xloginsert.c:368
void XLogBeginInsert(void)
Definition xloginsert.c:152
#define XLogRecGetInfo(decoder)
Definition xlogreader.h:409
#define XLogRecGetData(decoder)
Definition xlogreader.h:414
#define XLogRecHasAnyBlockRefs(decoder)
Definition xlogreader.h:416
bool InRecovery
Definition xlogutils.c:50