ITPub博客

首页 > 数据库 > > 系统管理函数-通用文件访问函数

系统管理函数-通用文件访问函数

作者:GaussDB_数据库 时间:2020-01-15 16:18:43 0 删除 编辑

通用文件访问函数提供了对数据库服务器上的文件的本地访问接口。只有数据库集群目录和log_directory目录里面的文件可以访问。使用相对路径访问集群目录里面的文件,以及匹配log_directory配置而设置的路径访问日志文件。只有数据库系统管理员才能使用这些函数。

  • pg_ls_dir(dirname text)

    描述:列出目录中的文件。

    返回值类型:setof text

    备注:pg_ls_dir返回指定目录里面的除了特殊项“.”和“..”之外所有名字。

    示例:

    SELECT pg_ls_dir('./');
    pg_ls_dir
    ----------------------
    .postgresql.conf.swp
    postgresql.conf
    pg_tblspc
    PG_VERSION
    pg_ident.conf
    core
    server.crt
    pg_serial
    pg_twophase
    postgresql.conf.lock
    pg_stat_tmp
    pg_notify
    pg_subtrans
    pg_ctl.lock
    pg_xlog
    pg_clog
    base
    pg_snapshots
    postmaster.opts
    postmaster.pid
    server.key.rand
    server.key.cipher
    pg_multixact
    pg_errorinfo
    server.key
    pg_hba.conf
    pg_replslot
    .pg_hba.conf.swp
    cacert.pem
    pg_hba.conf.lock
    global
    gaussdb.state
    (32 rows)
  • pg_read_file(filename text, offset bigint, length bigint)

    描述:返回一个文本文件的内容。

    返回值类型:text

    备注:pg_read_file返回一个文本文件的一部分,从offset开始,最多返回length字节(如果先达到文件结尾,则小于这个数值)。如果offset是负数,则它是相对于文件结尾回退的长度。如果省略了offset和length,则返回整个文件。

    示例:

    SELECT pg_read_file('postmaster.pid',,100);
    pg_read_file
    ---------------------------------------
    53078 +
    /srv/BigData/hadoop/data1/coordinator+
    1500022474 +
    25308 +
    /var/run/FusionInsight +
    localhost +
    2
    (1 row)
  • pg_read_binary_file(filename text [, offset bigint, length bigint,missing_ok boolean])

    描述:返回一个二进制文件的内容。

    返回值类型:bytea

    备注:pg_read_binary_file的功能与pg_read_file类似,除了结果的返回值为bytea类型不一致,相应地不会执行编码检查。与convert_from函数结合,这个函数可以用来读取用指定编码的一个文件。

    SELECT convert_from(pg_read_binary_file('filename'), 'UTF8');
    pg_stat_file(filename text)
  • 描述:返回一个文本文件的状态信息。

    返回值类型:record

    备注:pg_stat_file返回一条记录,其中包含:文件大小、最后访问时间戳、最后更改时间戳、最后文件状态修改时间戳以及标识传入参数是否为目录的boolean值。典型的用法:

    SELECT * FROM pg_stat_file('filename');
    SELECT (pg_stat_file('filename')).modification;
    示例:
    SELECT convert_from(pg_read_binary_file('postmaster.pid'), 'UTF8');
    convert_from
    --------------------------------------
    4881 +
    /srv/BigData/mppdb/data1/coordinator+
    1496308688 +
    25308 +
    /opt/huawei/Bigdata/mppdb/mppdb_tmp +
    * +
    25308001 43352069 +

    (1 row)
    SELECT * FROM pg_stat_file('postmaster.pid');

    size | access | modification | change
    | creation | isdir
    ------+------------------------+------------------------+------------------------
    +----------+-------
    117 | 2017-06-05 11:06:34+08 | 2017-06-01 17:18:08+08 | 2017-06-01 17:18:08+08
    | | f
    (1 row)
    SELECT (pg_stat_file('postmaster.pid')).modification;
    modification
    ------------------------
    2017-06-01 17:18:08+08
    (1 row)


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69959250/viewspace-3120269/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2020-01-06

  • 博文量
    2907
  • 访问量
    19280