{"id":174,"date":"2023-07-26T14:33:44","date_gmt":"2023-07-26T05:33:44","guid":{"rendered":"https:\/\/knowledge.comadori.com\/wp\/?p=174"},"modified":"2023-07-26T14:35:36","modified_gmt":"2023-07-26T05:35:36","slug":"postgresql-create-database-and-user","status":"publish","type":"post","link":"https:\/\/knowledge.comadori.com\/wp\/?p=174","title":{"rendered":"PostgreSQL create database and user"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">GOAL<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">PostgreSQL \u3067\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u4f5c\u6210\u3068\u30e6\u30fc\u30b6\u306e\u4f5c\u6210<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Creating a database and user in PostgreSQL<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">ENVIRONMENT<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>PostgreSQL 10+<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">PARAMETER<\/h2>\n\n\n\n<dl>\n<dt>database encoding<\/dt>\n<dd>PARAM_01: <input type=\"text\" name=\"PARAM_01\"><br>\ndefault: UTF8<\/dd>\n<\/dl>\n\n\n\n<dl>\n<dt>database name<\/dt>\n<dd>PARAM_02: <input type=\"text\" name=\"PARAM_02\"><\/dd>\n<\/dl>\n\n\n\n<dl>\n<dt>user name<\/dt>\n<dd>PARAM_03: <input type=\"text\" name=\"PARAM_03\"><\/dd>\n<\/dl>\n\n\n\n<dl>\n<dt>user password<\/dt>\n<dd>PARAM_04: <input type=\"text\" name=\"PARAM_04\"><\/dd>\n<\/dl>\n\n\n\n<dl>\n<dt>host name<\/dt>\n<dd>PARAM_05: <input type=\"text\" name=\"PARAM_05\"><\/dd>\n<\/dl>\n\n\n\n<h2 class=\"wp-block-heading\">CODE<\/h2>\n\n\n\n<script>\nconst param_reflector = (e) => {\n  let original_codes = [];\n  const reflection = () => {\n    original_codes.forEach((code) => {\n      let content = code.content;\n      document.querySelectorAll('[name^=\"PARAM_\"]').forEach((param, idx) => {\n        switch(param.type) {\n          case 'radio':\n            if (!param.checked) return;\n            break;\n          default:\n            if (!param.value) return;\n          }\n          content = content.replaceAll(`[${param.name}]`, param.value);\n          content = content.replaceAll(`<span class=\"token punctuation\">[<\/span>${param.name}<span class=\"token punctuation\">]<\/span>`, param.value);\n      });\nconsole.log(content)\n      code.elem.innerHTML = content;\n    });\n  };\n  setTimeout(() => {\n    document.querySelectorAll('.code code').forEach((elem, idx) => {\n      original_codes.push({elem: elem, content: elem.innerHTML});\n    }, 500);\n  });\n  document.querySelectorAll('[name^=\"PARAM_\"]').forEach((elem, idx) => {\n    elem.addEventListener('change', reflection);\n  });\n};\ndocument.addEventListener('DOMContentLoaded', param_reflector);\n<\/script>\n\n\n\n<h3 class=\"wp-block-heading\">create database<\/h3>\n\n\n\n<div class=\"hcb_wrap code\"><pre class=\"prism line-numbers lang-sql\" data-lang=\"SQL\"><code>CREATE DATABASE [PARAM_02] LC_COLLATE &#39;[PARAM_01]&#39; LC_CTYPE &#39;[PARAM_01]&#39; TEMPLATE template0;<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">create user<\/h3>\n\n\n\n<div class=\"hcb_wrap code\"><pre class=\"prism line-numbers lang-sql\" data-lang=\"SQL\"><code>CREATE USER [PARAM_03] WITH PASSWORD &#39;[PARAM_04]&#39;;<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">grant user<\/h3>\n\n\n\n<div class=\"hcb_wrap code\"><pre class=\"prism line-numbers lang-sql\" data-lang=\"SQL\"><code>GRANT ALL ON [PARAM_01].* to &#39;[PARAM_02]&#39;@&#39;%&#39;;\nGRANT ALL ON [PARAM_01].* to &#39;[PARAM_02]&#39;@&#39;localhost&#39;;<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading code\">grant user with host name<\/h3>\n\n\n\n<div class=\"hcb_wrap code\"><pre class=\"prism line-numbers lang-sql\" data-lang=\"SQL\"><code>GRANT ALL ON [PARAM_01].* to &#39;[PARAM_02]&#39;@&#39;[PARAM_04]&#39;;<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>PostgreSQL \u3067\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u4f5c\u6210\u3068\u30e6\u30fc\u30b6\u306e\u4f5c\u6210 Creating a database and user in PostgreSQL database encoding PARAM_01: default: U [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,15,14],"tags":[],"class_list":["post-174","post","type-post","status-publish","format-standard","hentry","category-database","category-mariadb","category-mysql-database"],"_links":{"self":[{"href":"https:\/\/knowledge.comadori.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/174","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/knowledge.comadori.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/knowledge.comadori.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/knowledge.comadori.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/knowledge.comadori.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=174"}],"version-history":[{"count":5,"href":"https:\/\/knowledge.comadori.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/174\/revisions"}],"predecessor-version":[{"id":179,"href":"https:\/\/knowledge.comadori.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/174\/revisions\/179"}],"wp:attachment":[{"href":"https:\/\/knowledge.comadori.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=174"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/knowledge.comadori.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=174"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/knowledge.comadori.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=174"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}