Pg::Snapshot USAGE

简介:

上面那篇PostgreSQL MVIEW的USAGE:

As database superuser (often postgres, but check for your system), do the following:

INSTALLATION

1.  Load PL/Perlu into your database.  See the createlang documents for details on how to do this;

2.  Make shure that DBI is installed on your Perl system and that the DBD of the database you choose is also installed;

3. Edit the Makefile.sh file and change the KEY variable to a better "secret" value and theBASE_SCHEMA variable to where the base(internal) Pg::Snapshot tables should be placed. Also remember to setup the remaining variables like SUPERUSER.

4.  On the PostgreSQL::Snapshots root, execute:
    # ./Makefile.sh

5. Load the database driver:
    - On PostgreSQL:
    # psql -d <database> -h <host> -U <user> -f ./drivers/pg/snapshot.sql
    - On Oracle, inside SQL+:
    SQL> @./drivers/oracle/snapshot.sql

6.  Load the pgsnapshots.sql file:
    # psql -d <database> -h <host> -U <user> -f pgsnapshots.sql

7. Allow the access from your workstation(or remote server) to one or more master tables on the current database:
    - Inside psql, conected as POSTGRES user:
    db=# select snapshot_do('<key>', 'ALLOW', '<masterschema>', '<mastername>', '<ip>');
    - or inside SQL+, conected as SYS user:
    SQL> begin
         snapshot_do('<key>', 'ALLOW', '<masterschema>', '<mastername>', '<ip>');
         end;
         /

    Where:
        <key> is the "secret" value placed on the KEY variable inside the Makefile.sh file.
        <masterschema> is the schema name of the master table you wish to allow access to
        <mastername> is the name of the master table you wish to allow access to
        <ip> is the IP address of your workstation/server to whom you wish to give access

8.  Use the underlying methods aka functions as needed.

AVAILABLE FUNCTIONS

1. create_dblink (implementation of "CREATE DBLINK")
    This function creates a link between databases. It takes the name of the DBLINK to be created and the necessary parameters do establish the remote connection.
    
    Syntax:
    create_dblink(dblinkname text, datasource text, username text, password text, attributes text)
    dblinkname: name of the DBLINK to be created
    datasource: Perl:DBI CONNECTION string to the remote database
    username: NAME of the remote database user
    password: PASSWORD of the remote database user
    attributes: connection ATTRIBUTES, like AutoCommit, RaiseErrors, etc.

2. drop_dblink (implementation of "DROP DBLINK")
    This function removes a link between databases taking only the DBLink name as a parameter.
    
    Syntax:
    drop_dblink(dblinkname text)
    dblinkname: name of the DBLINK to be removed

3. create_snapshot (implementation of "CREATE SNAPSHOT" or "CREATE MATERIALIZED VIEW")
    This function creates a materialized view or snapshot based on a query. The query can be referencing a database link or not.
    
    Syntax:
    create_snapshot(schemaname text, snapshotname text, query text, dblink text, refresh_method text, prebuilt_table text)
    schemaname: name of the schema where the snapshot will be created
    snapshotname: name of the snapshot to be created
    query: SQL query that will be executed at the remote database and which result will fill the snapshot
    dblink: optional parameter that take the name of the DBLink to be used. If the value is NULL, the query will be executed by the local database.
    refresh_method: can be "COMPLETE", "FAST" or "FORCE".
    prebuilt_table: name of the prebuilt table, on the same schema of the snapshot, over which the snapshot will be created (existing data are preserved). This is an optional parameter.

    IMPORTANT: the table will not be filled by this function.

4. drop_snapshot (implementation of "DROP SNAPSHOT" or "DROP MATERIALIZED VIEW")
    This function removes a materialized view or snapshot taking the schema name and the snapshot name as parameters.
    
    Syntax:
    drop_snapshot (schemaname text, snapshotname text)
    schemaname: name of the schema where the snapshot resides
    snapshotname: name of the snapshot to be removed

5. create_snapshot_log (implementation of "CREATE MATERIALIZED VIEW LOG" or "CREATE SNAPSHOT LOG")
    This function creates a log table bound to a master table. This log table allows the creation of fast refreshing snapshot(FAST REFRESH).

    Syntax:
    create_snapshot_log (schemaname text, mastername text, withwhat text)
    schemaname: name of the schema where the master table resides
    mastername: name of the master table
    withwhat: use the this clause to indicate whether the snapshot log should record the primary key, the rowid, or both the primary key and rowid when rows in the master are updated. This clause also specifies whether the snapshot records filter columns, which are non-primary-key columns referenced by subquery snapshots. The syntax is:
        1) "PRIMARY KEY": indicate that the primary key of all rows updated in the master table should be recorded in the snapshot log;
        2) "OID": indicate that the OID of all rows updated in the master table should be recorded in the snapshot log;
        3) "(<filter-columns>)" : a parenthesis-delimited comma-separated list that specifies the filter columns to be recorded in the snapshot log. For fast-refreshable primary-key snapshots defined with subqueries, all filter columns referenced by the defining subquery must be recorded in the snapshot log;
        4) Any combination of the above in any order.

6. drop_snapshot_log (implementation of "DROP MATERIALIZED VIEW LOG" or "DROP SNAPSHOT LOG")
    This function removes a log table previously bound to a master table.

    Syntax:
    drop_snapshot_log (schemaname text, mastername text)
    schemaname: name of the schema where the master table resides
    mastername: name of the master table

5. refresh_snapshot (implementation of "DBMS_SNAPSHOTS.REFRESH")
    This function refreshes the data on a materialized view or snapshot taking the schema and snapshot names as parameters.
    
    Syntax:
    refresh_snapshot (schemaname text, snapshotname text)
    schemaname: name of the schema where the snapshot resides
    snapshotname: name of the snapshot to be refreshed

相关文章
|
6天前
|
云安全 人工智能 自然语言处理
|
10天前
|
人工智能 Java API
Java 正式进入 Agentic AI 时代:Spring AI Alibaba 1.1 发布背后的技术演进
Spring AI Alibaba 1.1 正式发布,提供极简方式构建企业级AI智能体。基于ReactAgent核心,支持多智能体协作、上下文工程与生产级管控,助力开发者快速打造可靠、可扩展的智能应用。
931 33
|
5天前
|
机器学习/深度学习 人工智能 自然语言处理
Z-Image:冲击体验上限的下一代图像生成模型
通义实验室推出全新文生图模型Z-Image,以6B参数实现“快、稳、轻、准”突破。Turbo版本仅需8步亚秒级生成,支持16GB显存设备,中英双语理解与文字渲染尤为出色,真实感和美学表现媲美国际顶尖模型,被誉为“最值得关注的开源生图模型之一”。
558 4
|
7天前
|
机器学习/深度学习 人工智能 数据可视化
1秒生图!6B参数如何“以小博大”生成超真实图像?
Z-Image是6B参数开源图像生成模型,仅需16GB显存即可生成媲美百亿级模型的超真实图像,支持中英双语文本渲染与智能编辑,登顶Hugging Face趋势榜,首日下载破50万。
469 23
|
13天前
|
数据采集 人工智能 自然语言处理
Meta SAM3开源:让图像分割,听懂你的话
Meta发布并开源SAM 3,首个支持文本或视觉提示的统一图像视频分割模型,可精准分割“红色条纹伞”等开放词汇概念,覆盖400万独特概念,性能达人类水平75%–80%,推动视觉分割新突破。
840 59
Meta SAM3开源:让图像分割,听懂你的话
|
3天前
|
弹性计算 网络协议 Linux
阿里云ECS云服务器详细新手购买流程步骤(图文详解)
新手怎么购买阿里云服务器ECS?今天出一期阿里云服务器ECS自定义购买流程:图文全解析,阿里云服务器ECS购买流程图解,自定义购买ECS的设置选项是最复杂的,以自定义购买云服务器ECS为例,包括付费类型、地域、网络及可用区、实例、镜像、系统盘、数据盘、公网IP、安全组及登录凭证详细设置教程:
190 114
|
10天前
|
人工智能 前端开发 算法
大厂CIO独家分享:AI如何重塑开发者未来十年
在 AI 时代,若你还在紧盯代码量、执着于全栈工程师的招聘,或者仅凭技术贡献率来评判价值,执着于业务提效的比例而忽略产研价值,你很可能已经被所谓的“常识”困住了脚步。
517 46
大厂CIO独家分享:AI如何重塑开发者未来十年
|
6天前
|
存储 自然语言处理 测试技术
一行代码,让 Elasticsearch 集群瞬间雪崩——5000W 数据压测下的性能避坑全攻略
本文深入剖析 Elasticsearch 中模糊查询的三大陷阱及性能优化方案。通过5000 万级数据量下做了高压测试,用真实数据复刻事故现场,助力开发者规避“查询雪崩”,为您的业务保驾护航。
354 23