* PrepareTempTablespaces -- prepare to use temp tablespaces * * If we have not already done so in the current transaction, parse the * temp_tablespaces GUC variable and tell fd.c which tablespace(s) to use * for temp files. */
| 1886 | * for temp files. |
| 1887 | */ |
| 1888 | void |
| 1889 | PrepareTempTablespaces(void) |
| 1890 | { |
| 1891 | char *rawname; |
| 1892 | List *namelist; |
| 1893 | Oid *tblSpcs; |
| 1894 | int numSpcs; |
| 1895 | ListCell *l; |
| 1896 | |
| 1897 | /* No work if already done in current transaction */ |
| 1898 | if (TempTablespacesAreSet()) |
| 1899 | return; |
| 1900 | |
| 1901 | /* |
| 1902 | * Can't do catalog access unless within a transaction. This is just a |
| 1903 | * safety check in case this function is called by low-level code that |
| 1904 | * could conceivably execute outside a transaction. Note that in such a |
| 1905 | * scenario, fd.c will fall back to using the current database's default |
| 1906 | * tablespace, which should always be OK. |
| 1907 | */ |
| 1908 | if (!IsTransactionState()) |
| 1909 | return; |
| 1910 | |
| 1911 | /* Need a modifiable copy of string */ |
| 1912 | rawname = pstrdup(temp_tablespaces); |
| 1913 | |
| 1914 | /* Parse string into list of identifiers */ |
| 1915 | if (!SplitIdentifierString(rawname, ',', &namelist)) |
| 1916 | { |
| 1917 | /* syntax error in name list */ |
| 1918 | SetTempTablespaces(NULL, 0); |
| 1919 | pfree(rawname); |
| 1920 | list_free(namelist); |
| 1921 | return; |
| 1922 | } |
| 1923 | |
| 1924 | /* Store tablespace OIDs in an array in TopTransactionContext */ |
| 1925 | tblSpcs = (Oid *) MemoryContextAlloc(TopTransactionContext, |
| 1926 | list_length(namelist) * sizeof(Oid)); |
| 1927 | numSpcs = 0; |
| 1928 | foreach(l, namelist) |
| 1929 | { |
| 1930 | char *curname = (char *) lfirst(l); |
| 1931 | Oid curoid; |
| 1932 | AclResult aclresult; |
| 1933 | |
| 1934 | /* Allow an empty string (signifying database default) */ |
| 1935 | if (curname[0] == '\0') |
| 1936 | { |
| 1937 | /* InvalidOid signifies database's default tablespace */ |
| 1938 | tblSpcs[numSpcs++] = InvalidOid; |
| 1939 | continue; |
| 1940 | } |
| 1941 | |
| 1942 | /* Else verify that name is a valid tablespace name */ |
| 1943 | curoid = get_tablespace_oid(curname, true); |
| 1944 | if (curoid == InvalidOid) |
| 1945 | { |
no test coverage detected