{"id":1423,"date":"2018-01-19T19:22:49","date_gmt":"2018-01-19T19:22:49","guid":{"rendered":"http:\/\/goofy-trucks.flywheelsites.com\/optimizing-postgresql-page-2\/"},"modified":"2018-01-19T19:24:46","modified_gmt":"2018-01-19T19:24:46","slug":"optimizing-postgresql-page-2","status":"publish","type":"post","link":"https:\/\/phpbuilder.com\/optimizing-postgresql-page-2\/","title":{"rendered":"Optimizing Postgresql Page 2"},"content":{"rendered":"<div class=\"phpbuilder-content\">\n<div class=\"phpbuilder-meta\">\n<div class=\"\">By PHP Builder Staff<\/div>\n<div class=\"\">on August 21, 2001<\/div>\n<\/p><\/div>\n<div id=\"overflow-content\">\n<h2>Optimizing<\/h2>\n<div class=\"articlePara\">\nOne of the first things I noticed after turning on the CGI program, was<br \/>\nthat although queries were returned almost as fast as from the previous<br \/>\nMySQL based system, the load on the server was much higher &#8212; in fact<br \/>\nalmost 90-percent! Then I started to go down into the<br \/>\nnitty-gritty of things. I had optimized MySQL before by greatly<br \/>\nincreasing cache and buffer sizes and by throwing more ram towards the<br \/>\nproblem.<\/div>\n<div class=\"articlePara\">\nThe single biggest thing that you have to do before running Postgresql,<br \/>\nis to provide enough shared buffer space. Let me repeat: provide<br \/>\nenough buffer space! Let&#8217;s say you have about 512MB of ram on a<br \/>\ndedicated database server, then you need to turn over about 75-percent<br \/>\nof it to this shared buffer. Postgresql does best when it can load most<br \/>\nor &#8212; even better &#8212; all of a table into its shared memory space. In<br \/>\nour case, since our database was fairly small, I decided to allocate<br \/>\n128MB of RAM towards the shared buffer space.  <\/div>\n<div class=\"articlePara\">\nThe file \/var\/lib\/pgsql\/data\/postgresql.conf contains settings for the<br \/>\ndatabase server. Postgresql uses system shared memory as a buffer. On a<br \/>\nLinux system, you can see how much shared memory was allocated by your<br \/>\nsystem by running the command: <\/div>\n<div class=\"example\">\ncat \/proc\/sys\/kernel\/shmmax<\/div>\n<div class=\"articlePara\">\nAnd to view shared memory use on the system:<\/div>\n<div class=\"example\">ipcs<\/div>\n<div class=\"articlePara\">\nThe result will be in bytes. By default RedHat 7.1 allocates 32MB of<br \/>\nshared memory, hardly enough for postgresql. I increased this limit to<br \/>\n128MB by doing the command:<\/div>\n<div class=\"example\">echo 128000000 &gt; \/proc\/sys\/kernel\/shmmax<\/div>\n<div class=\"articlePara\">\nBe aware that once you reboot the server, this setting will disappear.<br \/>\nYou need to place this line in your postgresql startup file, or by<br \/>\nediting the \/etc\/sysctl.conf file for a more permanent setting.<\/div>\n<div class=\"articlePara\">\nThen in our postgresql.conf I set shared_buffers to 15200. Because<br \/>\nPostgresql uses 8K segments, I made a calculation of 128000\/8192 plus a<br \/>\n512K overhead. I also set our sort_mem to 32168 (32Megs for a sort memory<br \/>\narea). Since connection pooling was in effect, I set max_connections to 64.<br \/>\nAnd fsync was also set to false.<\/div>\n<div class=\"articlePara\">\n<pre>\nshared_buffers = 15200\nsort_mem = 32168\nmax_connections=64\nfsync=false\n<\/pre>\n<\/div>\n<div class=\"articlePara\">\nYou can read the manual to tweak other settings, but I never had the<br \/>\nneed to do so. Note that if you set shared_buffers to more than what<br \/>\nyour shared memory limit is, postgresql will refuse to start. This<br \/>\nconfused us for a while, since no logging was taking place. You can<br \/>\ntweak the startup file in \/etc\/init.d for the postmaster to write its<br \/>\noutput to a log file.<br \/>\nChange the fragment from:<\/div>\n<div class=\"articlePara\">\n<pre>\n\/postmaster start &gt; \/dev\/null 2&gt;\n<\/pre>\n<\/div>\n<div class=\"articlePara\">\nto<\/div>\n<div class=\"articlePara\">\n<pre>\n\/postmaster start &gt; \/var\/lib\/pgsql.log 2&gt;\n<\/pre>\n<\/div>\n<div class=\"articlePara\">\n<i>(or wherever you want to store the log.)<\/i><\/div>\n<\/div>\n<p><\/p>\n<div style=\"float: left; padding:15px; color:#17AAF3\">\n<div style=\"float:left; padding:2px;\"><a class=\"paginationPageLink\" href=\"smith20010821.html\">\u00ab Previous Page<\/a><\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"smith20010821.html\">1<\/a> <\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"background-color:#B6E5FC; font-size:16px; margin-top:1px; padding:1px 4px 1px 4px; color:#000; font-style:bold; float:left;\">2<\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"smith200108219ba9.html?page=3\">3<\/a> <\/div>\n<div style=\"float:left; padding:2px;\"><a class=\"paginationPageLink\" href=\"smith200108219ba9.html?page=3\">Next Page \u00bb<\/a><\/div>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>I decided to take a shot at installing and using this database. For most of our work I use MySQL and will continue to do so, because of its ease of<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1423","post","type-post","status-publish","format-standard","hentry","category-tutorials"],"_links":{"self":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1423","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/comments?post=1423"}],"version-history":[{"count":1,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1423\/revisions"}],"predecessor-version":[{"id":3282,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1423\/revisions\/3282"}],"wp:attachment":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/media?parent=1423"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/categories?post=1423"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/tags?post=1423"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}