如何在 PostgreSQL 的自定义表空间中创建数据库和表?

How to create database and tables in custom Tablespace in PostgreSQL?

我正在尝试在自定义 table 空间中创建数据库和 table,但是 'pg_default' table 空间用于 tables。这是示例:

mkdir /data

chown postgres /data

CREATE TABLESPACE mytspace OWNER postgres LOCATION '/data';

CREATE DATABASE mydb WITH OWNER = postgres ENCODING = 'UTF8' LC_COLLATE = 'ru_RU.utf8' LC_CTYPE = 'ru_RU.utf8' TABLESPACE = mytspace  CONNECTION LIMIT = -1;

CREATE TABLE foo(i int) TABLESPACE mytspace;

psql 的 \db 命令显示 table 空间已创建

          List of tablespaces
    Name    |  Owner   |   Location    
------------+----------+---------------
 mytspace   | postgres | /data
 pg_default | postgres | 
 pg_global  | postgres | 
(3 rows)

在适当的 table 空间中创建数据库。这是我在 pgAdmin 中看到的 SQL:

CREATE DATABASE mydb
    WITH 
    OWNER = postgres
    ENCODING = 'UTF8'
    LC_COLLATE = 'ru_RU.utf8'
    LC_CTYPE = 'ru_RU.utf8'
    TABLESPACE = mytspace
    CONNECTION LIMIT = -1;

但是 table 创建于“pg_default” tablespace

CREATE TABLE foo
(
    i integer
)
WITH (
    OIDS = FALSE
)
TABLESPACE pg_default;

我应该怎么做才能在 'mytspace' table 空间中创建一个 'foo' table?

这似乎是 pgAdmin 4 v 1.0 中的错误。 GUI 和 SQL 源代码为创建的表显示错误的表空间,但为创建的数据库显示正确的表空间。 pgAdmin 3 v 1.22.1 正确显示所有内容。