日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

AntDB上使用表空间

發布時間:2024/4/13 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 AntDB上使用表空间 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>

查看表空間的語法幫助
postgres=# \h create tablespace Command: CREATE TABLESPACE Description: define a new tablespace Syntax: CREATE TABLESPACE tablespace_name[ OWNER { new_owner | CURRENT_USER | SESSION_USER } ]LOCATION 'directory'[ WITH ( tablespace_option = value [, ... ] ) ]
創建表空間

連接coordinator:

create tablespace tst_tbs location '/home/shboss/antdb/data/tablespace';

需要在集群涉及到的主機上都存在location指定的目錄,否則報錯:

postgres=# create tablespace tst_tbs location '/home/shboss/antdb/data/tablespace'; ERROR: Fail to process utility query on remote node. DETAIL: ERROR: directory "/home/shboss/antdb/data/tablespace" does not exist

在各個主機上創建目錄:

remote_cmd "mkdir -p /home/shboss/antdb/data/tablespace"

再次連接coordinator創建表空間:

postgres=# create tablespace tst_tbs location '/home/shboss/antdb/data/tablespace'; CREATE TABLESPACE
查看表空間信息

數據庫級別:

postgres=# \dbList of tablespacesName | Owner | Location ------------+--------+------------------------------------pg_default | shboss | pg_global | shboss | tst_tbs | shboss | /home/shboss/antdb/data/tablespace (3 rows)postgres=# select * from pg_tablespace ;spcname | spcowner | spcacl | spcoptions ------------+----------+--------+------------pg_default | 10 | | pg_global | 10 | | tst_tbs | 10 | | (3 rows)

文件系統:

coord節點:

[shboss@localhost1 pg_tblspc]$ pwd /home/shboss/antdb/data/coord/pg_tblspc

datanode 節點:

lrwxrwxrwx 1 shboss shboss 34 Jul 23 15:25 164514 -> /home/shboss/antdb/data/tablespace [shboss@localhost1 pg_tblspc]$ pwd /home/shboss/antdb/data/db1/pg_tblspc

表空間路徑:

[shboss@localhost1 pg_tblspc]$ cd /home/shboss/antdb/data/tablespace [shboss@localhost1 tablespace]$ ll total 12 drwx------ 2 shboss shboss 4096 Jul 23 15:25 PG_9.6_201608131_coord1 drwx------ 2 shboss shboss 4096 Jul 23 15:25 PG_9.6_201608131_coord5 drwx------ 2 shboss shboss 4096 Jul 23 15:25 PG_9.6_201608131_db1_2 [shboss@localhost1 tablespace]$ tree . . ├── PG_9.6_201608131_coord1 ├── PG_9.6_201608131_coord5 └── PG_9.6_201608131_db1_2
在表空間內建表
create table test_tbs (id int) tablespace tst_tbs;

查看表空間中的數據文件:

[shboss@localhost1 tablespace]$ tree . . ├── PG_9.6_201608131_coord1 │?? └── 13603 │?? └── 476507 ├── PG_9.6_201608131_coord5 │?? └── 13603 │?? └── 18025 └── PG_9.6_201608131_db1_2└── 13597└── 164515

使用其他普通用戶在tst_tbs 表空間下創建表:

bmsql5=> create table test_tbs (id int) tablespace tst_tbs; ERROR: permission denied for tablespace tst_tbs bmsql5=>

解決辦法1:給普通用戶賦權

postgres=# grant create on tablespace tst_tbs to bmsql5_ora_fdw; GRANT

再次建表成功:

bmsql5=> create table test_tbs (id int) tablespace tst_tbs; CREATE TABLE bmsql5=> \d+ test_tbsTable "bmsql5_ora_fdw.test_tbs"Column | Type | Modifiers | Storage | Stats target | Description --------+---------+-----------+---------+--------------+-------------id | integer | | plain | | Tablespace: "tst_tbs" Distribute By: HASH(id) Location Nodes: ALL DATANODESbmsql5=>

在創建之前,可以查詢當前用戶表空間tst_tbs 是否有權限:

bmsql5=> select has_tablespace_privilege('tst_tbs','create');has_tablespace_privilege --------------------------t (1 row)

revoke權限后再次查詢:

-- superuser postgres=# revoke create on tablespace tst_tbs from bmsql5_ora_fdw; REVOKE -- 普通用戶 bmsql5=> select has_tablespace_privilege('tst_tbs','create');has_tablespace_privilege --------------------------f (1 row)

解決辦法2:修改表空間的屬主為表的創建用戶

alter tablespace tst_tbs owner to bmsql5_ora_fdw;

再次建表成功:

bmsql5=> create table test_tbs (id int) tablespace tst_tbs; CREATE TABLE bmsql5=>

解決辦法3:修改數據庫的默認表空間

alter database bmsql5 set tablespace tst_tbs;postgres=# alter database bmsql5 set tablespace tst_tbs; ALTER DATABASE Time: 323772.143 ms postgres=# postgres=# \l+ List of databasesName | Owner | Encoding | Collate | Ctype | Access privileges | Size | Tablespace | Description -----------+--------+----------+---------+-------+-------------------+---------+------------+--------------------------------------------bmsql5 | shboss | UTF8 | C | C | | 26 GB | tst_tbs | db1 | shboss | UTF8 | C | C | | 1529 MB | pg_default | postgres | shboss | UTF8 | C | C | | 43 MB | pg_default | default administrative connection databasetemplate0 | shboss | UTF8 | C | C | =c/shboss +| 30 MB | pg_default | unmodifiable empty database| | | | | shboss=CTc/shboss | | | template1 | shboss | UTF8 | C | C | =c/shboss +| 30 MB | pg_default | default template for new databases| | | | | shboss=CTc/shboss | | | testdb | shboss | UTF8 | C | C | | 108 MB | pg_default | (6 rows)

這個操作的耗時取決于數據庫的大小和磁盤的性能。且在數據文件移動過程中,該數據庫無法連接

[shboss@localhost1 tablespace]$ psql -d bmsql5 psql: FATAL: database "bmsql5" does not exist DETAIL: It seems to have just been dropped or renamed.

再次建表成功:

bmsql5=> create table test_tbs (id int) tablespace tst_tbs; CREATE TABLE bmsql5=> drop table test_tbs; DROP TABLE bmsql5=> create table test_tbs (id int); CREATE TABLE

碰到的問題:

更改的數據庫上有連接的時候,沒法修改:

postgres=# alter database bmsql5 set tablespace tst_tbs; ERROR: database "bmsql5" is being accessed by other users DETAIL: There is 1 other session using the database.

連接到修改的數據庫上也無法執行修改操作:

bmsql5=# alter database bmsql5 set tablespace tst_tbs; ERROR: cannot change the tablespace of the currently open database

如果修改的數據庫中已經有對象在目標表空間中,也無法執行操作:

postgres=# alter database bmsql5 set tablespace tst_tbs; ERROR: some relations of database "bmsql5" are already in tablespace "tst_tbs" HINT: You must move them back to the database's default tablespace before using this command.

查找指定表空間中的對象:

select relname,reltype,spcname from pg_class c, pg_tablespace tbs where c.reltablespace=tbs.oid and tbs.spcname='tst_tbs';
查看表的表空間
postgres=# \d test_tbsTable "public.test_tbs"Column | Type | Modifiers --------+---------+-----------id | integer | Tablespace: "tst_tbs"

如果表沒有使用所在數據庫的默認表空間,則會在\d 的時候顯示。

修改表的表空間
bmsql5=# select pg_relation_filepath('bmsql_stock');pg_relation_filepath ----------------------base/27636/461935 (1 row)bmsql5=# alter table bmsql_stock set tablespace tst_tbs; ALTER TABLE bmsql5=# select pg_relation_filepath('bmsql_stock');pg_relation_filepath -------------------------------------------------------pg_tblspc/476505/PG_9.6_201608131_coord1/27636/476515 (1 row)bmsql5=#

表很大的話,會比較耗時,是個挪動文件的過程,同時發現filenode是變了的。

查看表空間大小
postgres=# select pg_tablespace_size('tst_tbs');pg_tablespace_size --------------------36757504 (1 row)postgres=# select pg_size_pretty(pg_tablespace_size('tst_tbs'));pg_size_pretty ----------------35 MB (1 row)
刪除表空間
postgres=# drop tablespace tst_tbs; ERROR: tablespace "tst_tbs" is not empty

如果表空間中有對象刪除,則無法刪除。

根據上面提供的查找指定表空間中的對象 語句找出對象移走或刪除后,再進行刪除:

postgres=# drop tablespace tst_tbs; DROP TABLESPACE

查看主機上的文件:

[shboss@localhost1 tablespace]$ tree . .0 directories, 0 files [shboss@localhost1 tablespace]$ pwd /home/shboss/antdb/data/tablespace

目錄已經為空。

轉載于:https://my.oschina.net/yafeishi/blog/1861567

超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生

總結

以上是生活随笔為你收集整理的AntDB上使用表空间的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。