最近有客户想对数据库的用户权限做限制,需要用到copy的功能,不能确定其需要的权限,测试了一下:
highgo=# \c highgo testc
highgo=> select user;
current_user
--------------
testc
(1 row)
highgo=> copy testcopyto to '/hgdata/20180140.csv' with csv;
ERROR: 42501: must be superuser to COPY to or from a file
HINT: Anyone can COPY to stdout or from stdin. psql's \copy command also works for anyone.
testc为新建的普通用户,发现copy执行权限必须为超级用户。
[highgo@localhost ~]$ psql -h 10.254.23.240 -d highgo -U testc
Password for user testc:
psql (4.1.1)
PSQL: Release 4.1.1
Connected to:
HighGo Database V4.1 Enterprise Edition Release 4.1.1 - 64-bit Production
Type "help" for help.
highgo=> select user;
current_user
--------------
testc
(1 row)
highgo=> \dt
List of relations
Schema | Name | Type | Owner
--------+-----------------+-------+--------
public | quiz_dictionary | table | highgo
public | test | table | highgo
public | testcopyfrom | table | highgo
public | testcopyto | table | testc
(4 rows)
highgo=> \copy testcopyto to '/hgdata/testc1.sql'
COPY 1
\copy 则是普通用户就可以使用。
BY 海无涯