Postgres equivalent to Oracle's “DIRECTORY” objects

自古美人都是妖i 提交于 2020-12-14 05:01:11

问题


Is it possible to create "DIRECTORY" object in Postgres?

If not can some help me with a solution how implement it on PostgreSQL.


回答1:


Not the best option, but you could use:

COPY (select 1) TO PROGRAM 'mkdir --mode=777 -p /path/to/your/directory/'

Note that only the last part of directory get the permissions set in mode.




回答2:


The question doesn't even make sense really. PostgreSQL is a database management system. It doesn't have files and directories.

The closest parallel I can think of is schemas - see CREATE SCHEMA.

Now, if you want to use COPY to write output to the server's disk and want to create a directory to put that output in... then no, there's nothing like that. But you can use PL/Perlu or PL/Pythonu to do it easily enough.




回答3:


There is no equivalent concept to an "Oracle directory" in Postgres.

The alternatives depend on why the "Oracle directory" is needed.

If the directory is needed to read and write files on the database server, then this can be done through Generic File Access Functions. Access to those functions is restricted to superusers (details in the linked section of the manual). If regular users should be able to use them, the best thing would be to create wrapper functions and then grant execute on those functions to the users in question.

For security reasons, only directories inside the database cluster can be accessed.

But it's possible to create symlinks inside the data directory that point to directories outside the data directory. Access privileges on those directories need to be properly setup for the postgres operating system user (the one under which the postgres process is started)

If the directory is needed to access e.g. CSV files through Oracle's external tables, then there is no need for a "directory". The file FDW foreign data wrapper, can access files outside the data directory (provided access privileges have been setup correctly on the file system level).



来源:https://stackoverflow.com/questions/41608315/postgres-equivalent-to-oracles-directory-objects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!