当前位置:网站首页>Kingbasees plug-in KDB of Jincang database_ database_ link
Kingbasees plug-in KDB of Jincang database_ database_ link
2022-07-03 04:22:00 【Thousands of sails passed by the side of the sunken boat_】
1.Database Link Introduce
Database Link abbreviation DBLink, It is a mechanism provided by database management system for accessing external database objects . Used to pass through DBLink To access tables in an external database 、 View objects .DBLink Realize the communication between two databases .DBLink It includes a network-based data connection and the user name used to log in to the remote database 、 Password information . The local database system can be accessed through DBLink Establish a session with the remote database , So as to complete the access to remote database objects .DBLink Realized SQL/MED Some functions defined in the standard to access external data sources .
Note:
SQL/MED yes SQL Management of External Data Abbreviation , yes ISO/IEC 9075-9:2003 Standard middle right SQL Language extension .SQL/MED The standard specifies how to use an external data wrapper (Foreign Data Wrapper) And data connection (datalink) Achieve access to external data . External data here refers to data that can be based on SQL Of DBMS Data accessed .
dblink Object is a database internal object , Can pass dblink Object connection refers to objects in other databases . Support connection Oracle、Kingbase and Postgresql Of dblink object .
Related definitions are as follows :
Local database : The database to which the current database client is connected , You can directly access and operate objects with corresponding permissions in this database , The client holds the connection .
Remote database : By defining dblink Database accessed , Although the client seems to have direct access to the objects of the remote database , In fact, such connections are held by the local database , System information such as object definition does not exist in the local database . The remote database may just be connected to another service process or thread of its own by setting the local database .
Remote connection : adopt dblink Database connection created when accessing remote database objects , For the target database , The local database is the client for which it provides services . The local database has a remote connection to itself , Need reasonable management , Close it in time when necessary , Prevent excessive resource overhead .
remote table ( View 、 Materialized view ): Tables that exist on the remote database , It can also be views or materialized views , The local database doesn't care about this , Only care about the definition of the obtained data structure and the data itself .
Remote sequence : Sequence generators that exist on remote databases , Usually used to unify id Generation .
Remote functions ( stored procedure ): Functions or stored procedures that exist on remote databases , In general, there are many scenarios where functions are called remotely .
Remote synonyms : Exists in the local database pointing to remote objects ( surface 、 Sequence 、 Function, etc. ) A synonym for .
2. Database Link function
Dblink The function is mainly to meet the adaptation of common grammar , Let the code applied by users be applicable to a wider range of products without massive modification during migration :
Support connection management , Close the connection at the appropriate time to reduce the resource overhead of the remote database .
Support remote tables ( View 、 Materialized view ) Query for , And support push down query conditions to reduce the network overhead of data transmission .
Support remote table insertion .
Support remote sequence access .
3. establish Database Link object
Creating dblink Object to specify connection information , Include remote database network address 、 port 、 Database name 、 User name and password , What specific information needs to be provided will vary from database to database .
Grammar format :
CREATE [ PUBLIC ] DATABASE LINK dblink
CONNECT TO user IDENTIFIED BY password USING
{(connect_string) | config_tag };
Parameter description :
PUBLICAppoint PUBLIC Create public dblink object , All users can access public dblink object . public dblink Is created in PUBLIC Under Mode . Not specified PUBLIC Create private dblink, Don't be in PUBLIC Create private dblink.
dblinkSpecify the name of the database link to create , In the same mode dblink You can't have the same name .
user IDENTIFIED BY passwordSpecify the user name and password of the remote database .
connect_stringConfigure connection string information ,
connect_stringUsed to provide information for connecting to a remote database .
config_tagConfiguration file tag name , Used to indicate the profile (sys_database_link.conf) One of them , Thus, the network address of the remote database used to establish the database connection can be obtained through the configuration file 、 Port and database name .
annotation :
1、 The format in the configuration file is as follows :
[ name ]
DriverName= Connection driver name .
Host= Remote database network address .
Port= Remote database service port .
Dbname= Remote database name .
DbType= Remote database type .
DbType Support Oracle,Kingbase,Postgres There are three database types .
2、 When using this function , Need to kdb_database_link Join in shared_preload_libraries in .
3、 When querying the external database , You need to create the corresponding database plug-in , Such as :kingbase_fdw、oracle_fdw、postgres_fdw.
give an example :
Create one to Oracle Database connection of database , It can be used by all database users :
CREATE PUBLIC DATABASE LINK mylink CONNECT TO ‘SYSTEM’ IDENTIFIED BY ‘password’ USING 'ORADB';Create one to Oracle Database connection of database , Directly specify the connection string information :
CREATE PUBLIC DATABASE LINK mylink CONNECT TO ‘SYSTEM’ IDENTIFIED BY ‘password’ USING (DriverName=’Oracle ODBC Driver’, Host=192.168.0.1, Port=1521, Dbname=TEST, DbType=Oracle);
4. modify Database Link object
ALTER DATABASE LINK To modify a dblink Database objects .
The first form changes dblink The owner of the , To modify the owner , You must have this dblink And also a direct or indirect member of the newly owned role .
The second form changes dblink The name of , Only dblink The owner or super user can rename a dblink.
Grammar format :
ALTER [PUBLIC] DATABASE LINK dblink_name OWNER TO new_owner; ALTER [PUBLIC] DATABASE LINK dblink_name RENAME TO new_name;
Parameter description :
dblink_name
An existing dblink The name of ( It can be pattern Limited ).
new_owner
The dblink The user name of the new owner of .
dblink_name
The dblink New name for .
annotation :
ALTER DATABASE LINKThe syntax is similar to ALTER VIEW.
give an example :
hold
DATABASE LINKkdb_dblink_regress.link_d The owner is modified to kdb_dblink_user:ALTER DATABASE LINK kdb_dblink_regress.link_d OWNER TO kdb_dblink_user;
Compatibility :
ALTER DATABASE LINKThe statement is a KingbaseES Expand .
5. Delete Database Link object
DROP DATABASE LINK Remove a dblink. To execute this command, you must have this dblink Authority .
Grammar format :
DROP DATABASE LINK dblink_name
Parameter description :
dblink_nameDelete the name dblink_name Of
DATABASE LINK
annotation :
DBLink Can be owned and DBA Delete , Delete DBLink After object , All objects in the user session will be cleared .
If DBLink Being used by other users , Cannot delete this DBLink.
Temporary does not support PUBLIC keyword .
Compatibility :
The order is KingbaseES An extension of , compatible Oracle.
6. Database Link Permission control
For private DBLink, Its creator and DBA Have this DBLink Object to access . except DBLink Database users other than the creator can use PUBLIC Established by DBLink Visit .
The access rights of local users to remote database objects are controlled by the user authentication mechanism of the remote database system . adopt DBLink The local user who connects to the remote database will get the query permission owned by the user of the remote database .
7. DBLink Related views
DBLink The views provided to users are as follows :
| name | explain |
| ALL_DB_LINKS | Describe all database connections that the current user can access |
| USER_DB_LINKS | Describe all database connections owned by the current user |
| DBA_DB_LINKS | describe DBA All database connections that can be accessed |
8. DATABASE LINK DML
DATABASE LINK — dblink Of DML operation
Grammar format :
INSERT
[ WITH [ RECURSIVE ] with_query [, ...] ] INSERT INTO [email protected] [ AS alias ] [ ( column_name [, ...] ) ] [ OVERRIDING { SYSTEM | USER} VALUE ] { VALUES ( { expression } [, ...] ) [, ...] | query } [ RETURNING * | output_expression [ [ AS ] output_name ] [, ...] ] UPDATE
[ WITH [ RECURSIVE ] with_query [, ...] ] UPDATE [email protected] [ * ] [ [ AS ] alias ] SET { column_name = { expression } | ( column_name [, ...] ) = [ ROW ] ( { expression } [, ...] ) | ( column_name [, ...] ) = ( sub-SELECT ) } [, ...] [ FROM from_list ] [ WHERE condition ] [ RETURNING * | output_expression [ [ AS ] output_name ] [, ...] ] DELETE
[ WITH [ RECURSIVE ] with_query [, ...] ] DELETE FROM [email protected] [ * ] [ [ AS ] alias ] [ WHERE condition ] [ RETURNING * | output_expression [ [ AS ] output_name ] [, ...] ]
describe :
Use dblink Insert the remote table , to update , Delete .
Parameters :
dblinkdblink The name of , Use
CREATE DATABASE LINKCreated dblink Name of the database connection .
with_query
WITHClause allows you to specify one or more subqueries , stayINSERTUPDATEDELETEThe name of the subquery can be used to refer to them in the query See WITH Inquire about ( Common table expressions ) and SELECT .
table_nameThe name of an existing table ( Can be defined by patterns ).
aliasAlternate name of the target table name . When an alias is provided , It will completely hide the actual name of the table .
column_namebe known as
table_nameA column in the table of The name of , You can use the table name ( Can be qualified by the schema name ) Make a limit . If necessary, , Column names can also use a subdomain ( Subdomain name and table name are required 、 The schema name is qualified with parentheses ) Or array subscript qualification .
expressionThe expression or value to be assigned to the corresponding column .
output_expressionAfter each row is inserted or updated or deleted by
INSERTorUPUDATEorDELETEThe command calculates and returns expression . The expression can use ``table_name`` Any column in the specified table . It's written in*You can return all columns of inserted or updated or deleted rows .
output_nameThe name to be used for the returned column .
conditionOne can return
booleanThe expression of the value . Only let this expression returntrueThe row of will be updated , Delete .
Usage restriction :
INSERT
Remote table insert operation is not supported ON CONFLICT Clause
The value of the specified generated column is not supported
about RETURNING, I won't support it RETURNING ctid Wait for the system column
The default value of column is not supported at present , For remote tables with default values , It's going on insert When , If you explicitly use, for example insert into {tablename} default value perhaps insert into {tablename} values(default) Will report a mistake dblink not support insert with default value; If insert into When , If you do not specify all the columns, the above error will be reported, such as when the table tab There are two columns a, b When , Then below sql All will report wrong.
insert into [email protected] values(1)
insert into [email protected](a) values(1)
insert into [email protected] select a from tab
insert into [email protected](a) select a from tab
UPDATE
When the remote table is an inherited table , Only updating parent table data is not supported , Appoint ONLY Keyword times error
about RETURNING, I won't support it RETURNING ctid Wait for the system column
at present update Default values for columns are not supported , It's going on update When , If you explicitly specify the default value , such as update {tablenaem} set {columname}=default, Will report a mistake dblink not support insert with default value
Currently not supported
WHERE CURRENT OF cursor_nameUsage ofat present update about
Partition tableandInheritance tableYour behavior is uncertain , So it's forbidden to use dblink Update remotePartition tableperhapsInheritance tableData inDELETE
When the remote table is an inherited table , Deleting only parent table data is not supported , Appoint ONLY Keyword times error
about RETURNING, I won't support it RETURNING ctid Wait for the system column
at present delete about
Partition tableandInheritance tableYour behavior is uncertain , So it's forbidden to use dblink Delete remotePartition tableperhapsInheritance tableData in
ORACLE compatible :
When dblink The database connection created is connected to Oracle When , In addition to the above use restrictions , at present dblink Not yet UPDATE and DELETE
9. DATABASE LINK MERGE
DATABASE LINK — dblink Of MERGE operation
Grammar format :
MERGE INTO [ schema. ] { [email protected] } [ [ AS ] target_table_alias ]
USING { [ schema. ] { source_table } [ [ AS ] source_table_alias ]
ON ( condition_expression )
[ merge_update_clause ]
[ merge_insert_clause ];
merge_update_clause:
WHEN MATCHED THEN
UPDATE SET column = { expr }[, column = { expr } ]...
[ where_clause ]
[ delete_clause ]
delete_clause:
[DELETE where_clause]
merge_insert_clause:
WHEN NOT MATCHED THEN
INSERT [ ( column [, column ]...) ]
VALUES ({ expr }[, { expr } ]...)
[ where_clause ]
where_clause:
WHERE condition
describe :
Use dblink Enter the remote table MERGE operation .
Parameters :
target_tableMERGE The name of the remote target table .
dblinkdblink The name of , Use
CREATE DATABASE LINKCreated dblink Name of the database connection .
source_tableMERGE The name of the source table . The source table can be a local table , Ordinary appearance , It can also be a dblink Remote table of , namely [email protected]
target_table_aliasMERGE Alias of the target table .
source_table_aliasMERGE Alias of source table .
exprThe expression or value to be assigned to the corresponding column .
condition_expressionSpecify the join conditions between the target table and the source table . If the condition is true , And it specifies WHEN MATCHED THEN UPDATE Clause , Then update the tuple of the matched target table ; otherwise , If the condition is false and WHEN NOT MATCHED THEN INSERT Clause , Then insert the target table .
merge_update_clauseWhen the target table and the source table ON When the condition is true , Execute the clause , That is, update the target table data . This update operation will trigger the trigger on the target table . The updated column cannot be ON The column referenced in the condition , When updating, you can use WHERE The condition indicates the row to be updated , Conditions can contain columns of the source table , You can also include the columns of the target table , When specified WHERE When the condition is false , Do not update .
delete_clauseDELETE Clause deletes only the target table and the source table ON Condition is true 、 And it is the updated record that meets the deletion conditions ,DELETE Clause does not affect INSERT Line inserted by item . Delete condition is applied to the updated record , It can be related to the source table , It can also be related to the target table , Or both . If ON Condition is true , But it does not meet the update conditions , No updated data , that DELETE No data will be deleted .
merge_insert_clauseWhen the target table and the source table ON When the condition is false , Execute the statement . You can specify the insertion condition , When inserting WHERE Conditions can only refer to columns in the source table .VALUES Only the columns in the source table can be referenced later , Cannot contain columns of the target table .
边栏推荐
- Busycal latest Chinese version
- The time has come for the domestic PC system to complete the closed loop and replace the American software and hardware system
- The longest subarray length with a positive product of 1567 recorded by leecode
- 【毕业季·进击的技术er】职场人的自白
- 2022 electrician (Advanced) examination papers and electrician (Advanced) examination skills
- Kubernetes源码分析(一)
- IPhone x forgot the boot password
- What are the Bluetooth headsets with good sound quality in 2022? Inventory of four high-quality Bluetooth headsets
- [NLP]—sparse neural network最新工作简述
- [brush questions] connected with rainwater (one dimension)
猜你喜欢

The 10th China Cloud Computing Conference · China Station: looking forward to the trend of science and technology in the next decade

深潜Kotlin协程(十九):Flow 概述

Data Lake three swordsmen -- comparative analysis of delta, Hudi and iceberg

跨境电商多商户系统怎么选

智能合约安全审计公司选型分析和审计报告资源下载---国内篇

The time has come for the domestic PC system to complete the closed loop and replace the American software and hardware system
![[文献阅读] Sparsity in Deep Learning: Pruning and growth for efficient inference and training in NN](/img/7e/50fa6f65b5a4f0bb60909f57daff56.png)
[文献阅读] Sparsity in Deep Learning: Pruning and growth for efficient inference and training in NN

Joint search set: the number of points in connected blocks (the number of points in a set)

JS实现图片懒加载

2022-07-02: what is the output of the following go language code? A: Compilation error; B:Panic; C:NaN。 package main import “fmt“ func main() { var a =
随机推荐
redis 持久化原理
FFMpeg filter
CVPR 2022 | Dalian Institute of technology proposes a self calibration lighting framework for low light level image enhancement of real scenes
[fxcg] inflation differences will still lead to the differentiation of monetary policies in various countries
跨境电商多商户系统怎么选
Competitive product analysis and writing
竞品分析撰写
2022 electrician (Advanced) examination papers and electrician (Advanced) examination skills
MySQL field userid comma separated save by userid query
PostgreSQL database high availability Patroni source code learning - etcd class
Drf--- quick start 01
2022-02-13 (347. Top k high frequency elements)
"Final review" 16/32-bit microprocessor (8086) basic register
Redraw and reflow
[set theory] ordered pair (ordered pair | ordered triple | ordered n ancestor)
[brush questions] find the number pair distance with the smallest K
arthas watch 抓取入参的某个字段/属性
服务器无法远程连接原因分析
Preliminary cognition of C language pointer
Two points -leetcode-540 A single element in an ordered array