{"id":197718,"date":"2013-10-16T06:57:03","date_gmt":"2013-10-16T02:57:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=197718"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=197718","title":{"rendered":"<span class=\"post_title\">\u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 postgresql<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u041f\u0440\u043e\u0447\u0438\u0442\u0430\u043b <a href=\"http:\/\/habrahabr.ru\/post\/196828\/\">\u0441\u0442\u0430\u0442\u044c\u044e<\/a> \u043e \u0440\u0430\u0437\u0433\u043e\u043d\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0432\u0441\u0442\u0430\u0432\u043e\u043a \u0432 \u0421\u0423\u0411\u0414 Oracle \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 \u043d\u0430 Java. \u0422\u0430\u043a \u043a\u0430\u043a \u0432 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u044f \u0440\u0430\u0431\u043e\u0442\u0430\u044e \u0441 postgresql, \u0442\u043e \u0440\u0435\u0448\u0438\u043b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0434\u0430\u0441\u0442 \u044d\u0442\u0430 \u0421\u0423\u0411\u0414 \u0432 \u0441\u0432\u044f\u0437\u043a\u0435 \u0441 \u0433\u043e\u043b\u0430\u043d\u0433\u043e\u043c.<br \/>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u0441\u0442\u0435\u043a: golang-1.1.2 + postgresql-9.3.1. <br \/>  \u0414\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0433\u043e\u043b\u0430\u043d\u0433\u043e\u0432\u0441\u043a\u0438\u0439 \u0434\u0440\u0430\u0439\u0432\u0435\u0440 \u0434\u043b\u044f postgresql. \u042f \u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0441\u044c \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u043e\u043c github.com\/lib\/pq, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b go get -u github.com\/lib\/pq.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h4>\u0421\u0440\u0435\u0434\u0430 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/h4>\n<p>  \u0414\u043e\u043c\u0430\u0448\u043d\u0438\u0439 \u0434\u0435\u0441\u043a\u0442\u043e\u043f \u0441 archlinux-x86_64, kernel-3.11.5, 4\u0413\u0411 RAM (\u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u0442\u0435\u0441\u0442\u0430 \u0431\u044b\u043b\u043e \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e 1.2\u0413\u0411), \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u0441\u0442\u0430\u0440\u0435\u043d\u044c\u043a\u0438\u0439 \u0448\u043f\u0438\u043d\u0434\u0435\u043b\u044c\u043d\u044b\u0439 HDD. \u041f\u043e\u0441\u0442\u0433\u0440\u0435\u0441 \u0431\u043e\u043b\u0435\u0435-\u043c\u0435\u043d\u0435\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d (\u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d shared_buffers \u0434\u043e 768\u041c\u0411 \u0438 max_connections \u0434\u043e 1000, + \u0435\u0449\u0435 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0442\u044e\u043d\u0438\u043d\u0433), \u043d\u043e \u0431\u0435\u0437 \u0445\u0430\u0440\u0434\u043a\u043e\u0440\u0430.<br \/>  \u0414\u043b\u044f \u0447\u0438\u0441\u0442\u043e\u0442\u044b \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430 \u043d\u0435 \u0434\u0435\u043b\u0430\u043b \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0433\u043e\u0440\u043e\u0443\u0442\u0438\u043d \u2014 \u0432\u0441\u0435 \u0432 1 \u043f\u043e\u0442\u043e\u043a.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0422\u0435\u043a\u0441\u0442 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"go\">\/* sql_insertion_test01.go   * Synthetic test for simple insert operations into postgresql database  * Call: .\/sql_insertion_test01  * Pls, do not use name &quot;insert_test&quot;, because this name is always used by go-pkg-system  *\/ package main  import (     _ &quot;github.com\/lib\/pq&quot;     &quot;database\/sql&quot;     &quot;fmt&quot;     &quot;time&quot; )  const DB_CONNECT_STRING =      &quot;host=localhost port=5432 user=your_role password=your_password dbname=your_database sslmode=disable&quot;  func main() {      db, err := sql.Open(&quot;postgres&quot;, DB_CONNECT_STRING)     defer db.Close()      if err != nil {         fmt.Printf(&quot;Database opening error --&gt;%v\\n&quot;, err)         panic(&quot;Database error&quot;)     }      init_database(&db)     make_insertion(&db)  }  \/*-----------------------------------------------------------------------------*\/ func init_database(pdb **sql.DB) {      db := *pdb      init_db_strings := []string{         &quot;DROP SCHEMA IF EXISTS sb CASCADE;&quot;,         &quot;CREATE SCHEMA sb;&quot;,         \/\/be careful - next multiline string is quoted by backquote symbol         `CREATE TABLE sb.test_data(          id serial,          device_id integer not null,          parameter_id integer not null,          value varchar(100),          event_ctime timestamp default current_timestamp,          constraint id_pk primary key (id));`}      for _, qstr := range init_db_strings {         _, err := db.Exec(qstr)          if err != nil {             fmt.Printf(&quot;Database init error --&gt;%v\\n&quot;, err)             panic(&quot;Query error&quot;)         }     }     fmt.Println(&quot;Database rebuilded successfully&quot;) }  \/*-----------------------------------------------------------------------------*\/ func make_insertion(pdb **sql.DB) {      db := *pdb     const TEST_NUMBER = 400000      \/\/ backquotes for next multiline string     const INSERT_QUERY = `insert into sb.test_data(device_id, parameter_id, value)                                   values ($1, $2, $3);`      insert_query, err := db.Prepare(INSERT_QUERY)     defer insert_query.Close()      if err != nil {         fmt.Printf(&quot;Query preparation error --&gt;%v\\n&quot;, err)         panic(&quot;Test query error&quot;)     }      t1 := time.Now()      for i := 0; i &lt; TEST_NUMBER; i++ {          _, err = insert_query.Exec(i, i, &quot;0&quot;)          if err != nil {             fmt.Printf(&quot;Query execution error --&gt;%v\\n&quot;, err)             panic(&quot;Error&quot;)         }     }      t2 := time.Since(t1)      fmt.Printf(&quot;%v queries are executed for %v seconds (%v per second)\\n&quot;,         TEST_NUMBER, t2.Seconds(), TEST_NUMBER\/t2.Seconds())      \/\/ do not forget clean up after work )     \/\/_, err = db.Query(&quot;TRUNCATE sb.test_data;&quot;) } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u0438\u0437 \u0442\u0435\u043a\u0441\u0442\u0430 \u2014 \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0439 \u0432 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438, \u0433\u043e\u0440\u043e\u0443\u0442\u0438\u043d, \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446 \u0438 \u043f\u0440\u043e\u0447\u0438\u0445 \u0443\u0445\u0438\u0449\u0440\u0435\u043d\u0438\u0439 \u2014 \u043f\u0440\u044f\u043c\u043e\u0439 \u0432\u0432\u043e\u0434.<br \/>  \u041d\u0443 \u0440\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f \u0441\u0432\u044f\u0437\u043a\u0430 prepare-exec.  <\/p>\n<h4>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b<\/h4>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u2014 16000-17000 \u0432\u0441\u0442\u0430\u0432\u043e\u043a \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443 \u043d\u0430 \u043c\u043e\u0435\u0439 \u043c\u0430\u0448\u0438\u043d\u0435.<br \/>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u044f\u0442 \u043e\u0442 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b TEST_NUMBER (\u0441\u0442\u0430\u0432\u0438\u043b 1000, 2000, 4000, 40000 \u0438 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0441\u044f \u043d\u0430 400000). \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u0445 \u0438 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442 \u0437\u0430\u0442\u044b\u043a, \u043d\u043e \u0434\u0443\u043c\u0430\u044e, \u0447\u0442\u043e \u0434\u043b\u044f \u0442\u0435\u043a\u0443\u0449\u0438\u0445 \u0446\u0435\u043b\u0435\u0439 \u0442\u0430\u043a\u043e\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0445\u0432\u0430\u0442\u0430\u0435\u0442.<br \/>  \u0420\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u043b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0445\u0443\u0434\u0448\u0438\u0435 \u0446\u0438\u0444\u0440\u044b \u0438 \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043b \u043f\u043e\u0432\u043e\u0437\u0438\u0442\u044c\u0441\u044f \u0441 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f\u043c\u0438, \u043d\u043e \u043d\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u043b\u043e\u0441\u044c.<\/p>\n<h4>\u0412\u044b\u0432\u043e\u0434\u044b<\/h4>\n<p>  \u0414\u0443\u043c\u0430\u044e, \u0447\u0442\u043e \u0442\u0435\u0441\u0442 \u0432\u0441\u0435 \u0436\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u2014 \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u043b\u0438\u0441\u044c \u0432 \u043a\u044d\u0448. \u041d\u0435 \u043f\u043e\u043a\u0438\u0434\u0430\u0435\u0442 \u043e\u0449\u0443\u0449\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u043f\u0440\u0438 \u043a\u0430\u043a\u0438\u0445-\u0442\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u043b \u0443\u043f\u0435\u0440\u0435\u0442\u044c\u0441\u044f \u0432 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0434\u0438\u0441\u043a\u043e\u0432\u043e\u0439 \u043f\u043e\u0434\u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u0414\u0430 \u0438 \u0434\u0435\u0441\u043a\u0442\u043e\u043f\u043d\u043e\u0435 \u044f\u0434\u0440\u043e \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u0430\u043c\u044f\u0442\u044c \u043f\u043e\u0431\u043e\u0434\u0440\u0435\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u0433\u043e.<br \/>  \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0447\u0442\u043e \u0430\u0432\u0442\u043e\u0440\u044b \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u0442\u0440\u044e\u043a. \u041d\u043e \u0442\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0441\u0447\u0438\u0442\u0430\u044e, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u0430\u044f \u0441\u0432\u044f\u0437\u043a\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0432\u043f\u043e\u043b\u043d\u0435 \u044e\u0437\u0430\u0431\u0435\u043b\u044c\u043d\u0430.    \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/197718\/\"> http:\/\/habrahabr.ru\/post\/197718\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u041f\u0440\u043e\u0447\u0438\u0442\u0430\u043b <a href=\"http:\/\/habrahabr.ru\/post\/196828\/\">\u0441\u0442\u0430\u0442\u044c\u044e<\/a> \u043e \u0440\u0430\u0437\u0433\u043e\u043d\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0432\u0441\u0442\u0430\u0432\u043e\u043a \u0432 \u0421\u0423\u0411\u0414 Oracle \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 \u043d\u0430 Java. \u0422\u0430\u043a \u043a\u0430\u043a \u0432 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u044f \u0440\u0430\u0431\u043e\u0442\u0430\u044e \u0441 postgresql, \u0442\u043e \u0440\u0435\u0448\u0438\u043b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0434\u0430\u0441\u0442 \u044d\u0442\u0430 \u0421\u0423\u0411\u0414 \u0432 \u0441\u0432\u044f\u0437\u043a\u0435 \u0441 \u0433\u043e\u043b\u0430\u043d\u0433\u043e\u043c.<br \/>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u0441\u0442\u0435\u043a: golang-1.1.2 + postgresql-9.3.1. <br \/>  \u0414\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0433\u043e\u043b\u0430\u043d\u0433\u043e\u0432\u0441\u043a\u0438\u0439 \u0434\u0440\u0430\u0439\u0432\u0435\u0440 \u0434\u043b\u044f postgresql. \u042f \u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0441\u044c \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u043e\u043c github.com\/lib\/pq, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b go get -u github.com\/lib\/pq.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-197718","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/197718","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=197718"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/197718\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=197718"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=197718"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=197718"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}