Efficiency chapter-SQL Self-service query platform

Source: Internet
Author: User

usage Time : 2014-05-present.


Upgrades & changes : No changes have been made to the stocking status after commissioning.


operating conditions : use in the internal environment, daily share of DBA workload 500 times + query.


background : DBA number -3,DBA In addition to routine maintenance and database optimization, it takes a lot of time to develop and query for non-sensitive data.


Requirements : 1. The query does not affect the online database service; 2. To do restful API docking with existing operation and maintenance system;

3. Can not receive data Super 1000 + query, in case it is easy to maliciously guide the data; 4. Prevent malicious actions (Delete, update, create TABLE, and so on).

Compare objects: PhpMyAdmin (1. There is too much security to discover the functionality, 2. Need to install web and corresponding PHP services and code, maintenance workload (for example: Java Web container system, each additional data source restart service);

3. Can not satisfy all need to use immediately)

Because the front-end presence operation platform, database query function can be implemented in two ways:

1. Develop multiple function modules in the original operation and maintenance platform, but will cause the operation and maintenance platform bloated, if the volume of large need to increase resources, the expansion is cumbersome.

2. Using Nginx to query the database of third-party tools to serve as a result of SQL operation results returned, at the same time, can achieve the class heat deployment mode effect, only in the discovery of new configuration, need to add nginx dynamically, re-configure Nginx can be formally serviced.

Based on the above reasons: the use of the approximate things decided. Nginx, LUA (do illegal character check + authorization authentication), Nginx module ngx_postgres (for querying pgsql), Nginx module Drizzle-nginx (for querying MySQL), Form-input-nginx-module (get post content directly, lazy, can actually be obtained in LUA code).


now use the diagram :

1. Work area

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M01/8E/75/wKiom1jA-rGgZoh_AACtKNPB0Xo546.jpg-wh_500x0-wm_ 3-wmp_4-s_2993675353.jpg "style=" Float:none; "title=" 1.jpg "alt=" Wkiom1ja-rggzoh_aactknpb0xo546.jpg-wh_50 "/>

2. Historical record Area

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M01/8E/73/wKioL1jA-rLSloOrAAB9o4B3QnA711.jpg-wh_500x0-wm_ 3-wmp_4-s_2187569603.jpg "style=" Float:none; "title=" 2.jpg "alt=" Wkiol1ja-rlslooraab9o4b3qna711.jpg-wh_50 "/>


Implementing the Schema :

Dimensional plane platform Web interface-> Nginx+lua (Database routing), Nginx + lua + drizzle-nginx + ngx_postgres + form-input-nginx-module (if performance is not enough, you need to Copy, clone, and resource, as long as the database is registered on the routing side of the line) API query interface public

Realize:

1. Compile.

Add--add-module=path/ngx_devel_kit-0.2.19--add-module=path/lua-nginx-module-0.9.7--add-module=PATH/in Nginx Rds-json-nginx-module-master (mainly automatic json of output results)--add-module=path/form-input-nginx-module--add-module=path/ngx_ Postgres-master--add-module=path/drizzle-nginx-module-0.1.7

Drizzle-nginx-modul = https://github.com/calio/form-input-nginx-module

Ngx_postgres = Https://github.com/FRiCKLE/ngx_postgres

Form-input-nginx-module = https://github.com/calio/form-input-nginx-module

2.nginx find the configuration in the database:

Mysql

Upstream name {

Drizzle_server DB ip:db Port dbname=xx

Password=xx user=xx Protocol=mysql Charset=utf8;

}

Show Table Features

Location ~ (database route ID) {

Set $upname $;

Set $my _sql ' show tables ';

Drizzle_query $my _sql;

Drizzle_pass $upname;

Drizzle_connect_timeout 10s; # Default 60s

Drizzle_send_query_timeout 60s; # Default 60s

Drizzle_recv_cols_timeout 30s; # Default 60s

Drizzle_recv_rows_timeout 30s; # Default 60s

Rds_json on;

}

Check table operation

Location ~ (Database routing information) {

Default_type ' Text/plain ';

Set_form_input $qsql;

Access_by_lua $sql '

Authorization and illegal character verification function module, verifying qsql

‘;

Set $upname $;

Lua_need_request_body on;

Client_max_body_size 50k;

Client_body_buffer_size 50k;

Drizzle_query $sql;

Drizzle_pass $upname;

Drizzle_connect_timeout 10s; # Default 60s

Drizzle_send_query_timeout 30s; # Default 60s

Drizzle_recv_cols_timeout 30s; # Default 60s

Drizzle_recv_rows_timeout 30s; # Default 60s

Rds_json on;

}

Pg

Upstream 192.168.236.1725432huayouhui_app {

Postgres_server DB ip:db Port dbname=xx

User=xx password=xx;

Postgres_keepalive off;

}

Tabular

Location ~ (routing information) {

Add_header Content-type ' text/html; Charset=utf-8 ';

Set $dbname $;

Set $upname $1$2;

Set_by_lua $quoted _name '

Local name = Ngx.var.dbname

Local MySQL = "SELECT tablename from pg_tables where schemaname=\ '". Name: " \‘;"

return MySQL

‘;

Postgres_pass $upname;

Rds_json on;

Postgres_query ' $quoted _name ';

}

Inquire

Location ~ (Database routing information) {

Add_header Content-type ' text/html; Charset=utf-8 ';

Set_form_input $qsql;

Access_by_lua $sql '

Authorization and illegal character verification function module, verifying qsql

‘;

Set $upname $;

Lua_need_request_body on;

Client_max_body_size 50k;

Client_body_buffer_size 50k;

Postgres_pass $upname;

Rds_json on;

Postgres_query ' $sql ';

}

Page implementation and testing on-line time: 3days;nginx routing + nginx query: implementation + Test 1day.



More articles please follow the subscription number light operation

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/8E/75/wKiom1jA-wKjPdPPAAAh5Y2gn5M693.jpg "title=" Dingyuehao.jpg "alt=" Wkiom1ja-wkjpdppaaah5y2gn5m693.jpg "/>

This article is from the "Light ops" blog, so be sure to keep this source http://qdywsky.blog.51cto.com/3129793/1904763

Efficiency chapter-SQL Self-service query platform

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.