Postgresql 中文操作指南

F.1. adminpack — pgAdmin support toolpack #

adminpack 提供了许多支持函数,pgAdmin 和其他管理工具可以使用这些函数以提供附加功能,如服务器日志文件的远程管理。默认情况下,仅允许数据库超级用户使用所有这些函数,但可以通过使用 GRANT 命令允许其他用户使用。

adminpack provides a number of support functions which pgAdmin and other administration and management tools can use to provide additional functionality, such as remote management of server log files. Use of all these functions is only allowed to database superusers by default, but may be allowed to other users by using the GRANT command.

Table F.1 中显示的函数提供对托管服务器的计算机上的文件的写访问权。(另请参见 Table 9.101 中的函数,它提供只读访问权。)仅当用户是超级用户或被赋予了针对函数适当的 pg_read_server_filespg_write_server_files 角色的特权时,才能访问数据库集群目录内的文件,但相对路径或绝对路径都是允许的。

The functions shown in Table F.1 provide write access to files on the machine hosting the server. (See also the functions in Table 9.101, which provide read-only access.) Only files within the database cluster directory can be accessed, unless the user is a superuser or given privileges of one of the pg_read_server_files or pg_write_server_files roles, as appropriate for the function, but either a relative or absolute path is allowable.

Table F.1. adminpack Functions

Table F.1. adminpack Functions

Function

Description

pg_catalog.pg_file_write ( filename text, data text, append boolean ) → bigint

Writes, or appends to, a text file.

pg_catalog.pg_file_sync ( filename text ) → void

Flushes a file or directory to disk.

pg_catalog.pg_file_rename ( oldname text, newname text [, archivename text ] ) → boolean

Renames a file.

pg_catalog.pg_file_unlink ( filename text ) → boolean

Removes a file.

pg_catalog.pg_logdir_ls () → setof record

Lists the log files in the log_directory directory.

pg_file_write 将指定的 data 写入由 filename 命名的文件中。如果 append 为 false,则该文件一定不存在。如果 append 为 true,则该文件可以已存在,并在存在时附加。返回写入的字节数。

pg_file_write writes the specified data into the file named by filename. If append is false, the file must not already exist. If append is true, the file can already exist, and will be appended to if so. Returns the number of bytes written.

pg_file_sync fsync 由 filename 命名的指定文件或目录。在失败时,会引发错误(例如,指定的没有文件)。请注意, data_sync_retry 对此函数没有影响,因此,即使无法刷新数据库文件,也不会引发 PANIC 级别错误。

pg_file_sync fsyncs the specified file or directory named by filename. An error is thrown on failure (e.g., the specified file is not present). Note that data_sync_retry has no effect on this function, and therefore a PANIC-level error will not be raised even on failure to flush database files.

pg_file_rename 重命名一个文件。如果省略或为 NULL,则会直接将 oldname 重命名为 newname(这必须不存在)。如果提供了 archivename,它会首先将 newname 重命名为 archivename(这必须不存在),然后将 oldname 重命名为 newname。在第二步重命名的步骤中,如果发生了失败,它会尝试在报告错误之前将 archivename 重命名回 newname。成功时返回 true,如果源文件不存在或不可写,则返回 false;其他情况抛出错误。

pg_file_rename renames a file. If archivename is omitted or NULL, it simply renames oldname to newname (which must not already exist). If archivename is provided, it first renames newname to archivename (which must not already exist), and then renames oldname to newname. In event of failure of the second rename step, it will try to rename archivename back to newname before reporting the error. Returns true on success, false if the source file(s) are not present or not writable; other cases throw errors.

pg_file_unlink 删除指定的文件。成功时返回 true,如果指定的源文件不存在或 unlink() 调用失败,则返回 false;其他情况抛出错误。

pg_file_unlink removes the specified file. Returns true on success, false if the specified file is not present or the unlink() call fails; other cases throw errors.

pg_logdir_ls 返回 log_directory 目录中所有日志文件的开始时间戳和路径名称。 log_filename 参数必须具有其默认设置 (postgresql-%Y-%m-%d%H%M%S.log_) 才能使用此函数。

pg_logdir_ls returns the start timestamps and path names of all the log files in the log_directory directory. The log_filename parameter must have its default setting (postgresql-%Y-%m-%d%H%M%S.log_) to use this function.