当前位置:网站首页>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 .
边栏推荐
- FFMpeg example
- Five elements of user experience
- [NLP]—sparse neural network最新工作简述
- Dive Into Deep Learning——2.1数据操作&&练习
- Nat. Comm. | use tensor cell2cell to deconvolute cell communication with environmental awareness
- Xrandr modifier la résolution et le taux de rafraîchissement
- Application of I2C protocol of STM32F103 (read and write EEPROM)
- Redraw and reflow
- 因果AI,下一代可信AI的产业升级新范式?
- [software testing-6] & Test Management
猜你喜欢

Is it better to speculate in the short term or the medium and long term? Comparative analysis of differences

Basic MySQL operations

Esp32 series (3): GPIO learning (take simple GPIO input and output, ADC, DAC as examples)

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 =

Feature_selection

Pdf editing tool movavi pdfchef 2022 direct download

"Final review" 16/32-bit microprocessor (8086) basic register

Which Bluetooth headset is cost-effective? Four Bluetooth headsets with high cost performance are recommended

vulnhub HA: Natraj

JS realizes lazy loading of pictures
随机推荐
[set theory] set operation (Union | intersection | disjoint | relative complement | symmetric difference | absolute complement | generalized union | generalized intersection | set operation priority)
Mila, University of Ottawa | molecular geometry pre training with Se (3) invariant denoising distance matching
服务器无法远程连接原因分析
拆一辆十万元的比亚迪“元”,快来看看里面的有哪些元器件。
xrandr修改分辨率與刷新率
2022-02-14 (394. String decoding)
Nat. Comm. | use tensor cell2cell to deconvolute cell communication with environmental awareness
MySQL timestampdiff interval
The 10th China Cloud Computing Conference · China Station: looking forward to the trend of science and technology in the next decade
MySQL field userid comma separated save by userid query
FFMpeg example
金仓数据库KingbaseES 插件kdb_exists_expand
GFS分布式文件系统(光是遇见已经很美好了)
Joint set search: merge intervals and ask whether two numbers are in the same set
Sklearn data preprocessing
sklearn数据预处理
[nlp] - brief introduction to the latest work of spark neural network
Database management tool, querious direct download
The longest subarray length with a positive product of 1567 recorded by leecode
[set theory] inclusion exclusion principle (including examples of exclusion principle)