当前位置:网站首页>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 :
PUBLIC
Appoint 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.
dblink
Specify the name of the database link to create , In the same mode dblink You can't have the same name .
user IDENTIFIED BY password
Specify the user name and password of the remote database .
connect_string
Configure connection string information ,
connect_string
Used to provide information for connecting to a remote database .
config_tag
Configuration 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 LINK
The syntax is similar to ALTER VIEW.
give an example :
hold
DATABASE LINK
kdb_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 LINK
The 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_name
Delete 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 :
dblink
dblink The name of , Use
CREATE DATABASE LINK
Created dblink Name of the database connection .
with_query
WITH
Clause allows you to specify one or more subqueries , stayINSERT
UPDATE
DELETE
The name of the subquery can be used to refer to them in the query See WITH Inquire about ( Common table expressions ) and SELECT .
table_name
The name of an existing table ( Can be defined by patterns ).
alias
Alternate name of the target table name . When an alias is provided , It will completely hide the actual name of the table .
column_name
be known as
table_name
A 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 .
expression
The expression or value to be assigned to the corresponding column .
output_expression
After each row is inserted or updated or deleted by
INSERT
orUPUDATE
orDELETE
The 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_name
The name to be used for the returned column .
condition
One can return
boolean
The expression of the value . Only let this expression returntrue
The 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_name
Usage ofat present update about
Partition table
andInheritance table
Your behavior is uncertain , So it's forbidden to use dblink Update remotePartition table
perhapsInheritance table
Data 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 table
andInheritance table
Your behavior is uncertain , So it's forbidden to use dblink Delete remotePartition table
perhapsInheritance table
Data 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_table
MERGE The name of the remote target table .
dblink
dblink The name of , Use
CREATE DATABASE LINK
Created dblink Name of the database connection .
source_table
MERGE 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_alias
MERGE Alias of the target table .
source_table_alias
MERGE Alias of source table .
expr
The expression or value to be assigned to the corresponding column .
condition_expression
Specify 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_clause
When 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_clause
DELETE 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_clause
When 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 .
边栏推荐
- ZIP文件的导出
- xrandr修改分辨率與刷新率
- [mathematical logic] predicate logic (judge whether the first-order predicate logic formula is true or false | explain | example | predicate logic formula type | forever true | forever false | satisfi
- [untitled] 2022 safety production supervisor examination question bank and simulated safety production supervisor examination questions
- 2022-02-14 (394. String decoding)
- How to connect WiFi with raspberry pie
- PostgreSQL database high availability Patroni source code learning - etcd class
- Fcpx template: sweet memory electronic photo album photo display animation beautiful memory
- Mongodb slow query optimization analysis strategy
- BMZCTF simple_ pop
猜你喜欢
使用BENCHMARKSQL工具对kingbasees并发测试时kill掉主进程成功后存在子线程未及时关闭
[fxcg] inflation differences will still lead to the differentiation of monetary policies in various countries
300+ documents! This article explains the latest progress of multimodal learning based on transformer
[brush questions] find the number pair distance with the smallest K
Database management tool, querious direct download
[Thesis Writing] how to write the overall design of JSP tourism network
Esp32 series (3): GPIO learning (take simple GPIO input and output, ADC, DAC as examples)
CVPR 2022 | Dalian Institute of technology proposes a self calibration lighting framework for low light level image enhancement of real scenes
深潜Kotlin协程(十九):Flow 概述
Feature_selection
随机推荐
Redis persistence principle
[set theory] set concept and relationship (true subset | empty set | complete set | power set | number of set elements | power set steps)
Small program animation realizes the running lantern and animation object
Database management tool, querious direct download
Analysis of the reason why the server cannot connect remotely
[set theory] set identities (idempotent law | exchange law | combination law | distribution rate | De Morgan law | absorption rate | zero law | identity | exclusion law | contradiction law | complemen
Design and implementation of kubelet garbage collection mechanism to protect nodes from being preempted by containers image GC high threshold
CVPR 2022 | Dalian Technology propose un cadre d'éclairage auto - étalonné pour l'amélioration de l'image de faible luminosité de la scène réelle
vulnhub HA: Natraj
"Final review" 16/32-bit microprocessor (8086) basic register
Square root of X
Basic types of data in TS
JS native common knowledge
Interaction free shell programming
Dive Into Deep Learning——2.1数据操作&&练习
Joint set search: merge intervals and ask whether two numbers are in the same set
Mila, University of Ottawa | molecular geometry pre training with Se (3) invariant denoising distance matching
leetcode:297. Serialization and deserialization of binary tree
Know that Chuangyu cloud monitoring - scanv Max update: Ecology OA unauthorized server request forgery and other two vulnerabilities can be detected
[untitled] 2022 safety production supervisor examination question bank and simulated safety production supervisor examination questions