{"id":1241,"date":"2023-07-14T16:36:35","date_gmt":"2023-07-14T08:36:35","guid":{"rendered":"https:\/\/www.yinyubo.com\/?p=1241"},"modified":"2023-07-14T16:41:06","modified_gmt":"2023-07-14T08:41:06","slug":"%e8%bf%81%e7%a7%bbdrone-io%e7%9a%84sqllite%e6%95%b0%e6%8d%ae%e5%ba%93%e5%88%b0postgresql%e6%95%b0%e6%8d%ae%e5%ba%93","status":"publish","type":"post","link":"https:\/\/www.yinyubo.com\/?p=1241","title":{"rendered":"\u8fc1\u79fbdrone.io\u7684sqlite\u6570\u636e\u5e93\u5230postgresql\u6570\u636e\u5e93"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u80cc\u666f<\/h2>\n\n\n\n<p>drone.io\u9ed8\u8ba4\u5b89\u88c5\u7684\u65f6\u5019\u662f\u4f7f\u7528sqlite\u6570\u636e\u5e93\uff0c\u53ef\u4ee5\u7528\u4e8e\u6f14\u793a\u4ea7\u54c1\uff0c\u4f46\u662f\u4e00\u65e6git\u4ed3\u5e93\u6570\u91cf\u8fc7\u591a\uff0cbuild\u6b21\u6570\u8fc7\u591a\u4e4b\u540e\uff0c\u4f1a\u8d8a\u7528\u8d8a\u5361\uff0c\u4ece\u957f\u8fdc\u6765\u770b\uff0c\u60f3\u7528\u4e8e\u751f\u4ea7\u73af\u5883\uff0c\u8fd8\u662f\u5f97\u8f6c\u5411postgresql\u6570\u636e\u5e93\u3002\u5173\u4e8epostgresql\u6570\u636e\u5e93\u7684\u914d\u7f6e\u53ef\u4ee5\u53c2\u8003\u5982\u4e0b\u9875\u9762\u3002\u4e3b\u8981\u662f\u8bbe\u7f6e\u4e00\u4e2a\u6570\u636e\u5e93\u6765\u6e90\u548cpostgresql\u6570\u636e\u5e93\u8fde\u63a5\u4e32\u4fe1\u606f<\/p>\n\n\n\n<p><a href=\"https:\/\/docs.drone.io\/server\/storage\/database\/#postgres\">https:\/\/docs.drone.io\/server\/storage\/database\/#postgres<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9e\u65bd\u6b65\u9aa4<\/h2>\n\n\n\n<p><strong>1.\u627e\u5230drone.io\u7684\u539f\u59cbsqlite\u6570\u636e\u5e93\u3002<\/strong><\/p>\n\n\n\n<p>\u5982\u679c\u6211\u4eec\u91c7\u7528\u7684\u662fkubernetes\u7684helmchart\u5b89\u88c5\uff0c\u4e00\u822c\u4f1a\u5728drone\u547d\u540d\u7a7a\u95f4\u91cc\u7684pvc\u91cc\u627e\u5230\uff0c\u53ef\u4ee5\u901a\u8fc7 kubectl\u547d\u4ee4\u53bb\u627e <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl get pvc -n drone\nkubectl get pv \nkubectl describe pv $(drone\u7684pv\u540d\u5b57)<\/code><\/pre>\n\n\n\n<p>\u627e\u5230\u5b58\u50a8\u4f4d\u7f6e\u540e\uff0c\u5177\u4f53\u7684sqlite\u6570\u636e\u5e93\u6587\u4ef6\u53ebdatabase.sqlite \u53ef\u4ee5\u901a\u8fc7CP\u547d\u4ee4\u590d\u5236\u4e00\u4efddatabase.sqlite\u51fa\u6765\u5907\u4efd<\/p>\n\n\n\n<p><strong>2.\u5b89\u88c5postgresql\u6570\u636e\u5e93<\/strong><\/p>\n\n\n\n<p>postgresql\u6570\u636e\u5e93\u7684\u5b89\u88c5\u8fd8\u662f\u6bd4\u8f83\u7b80\u5355\u7684\uff0c\u5b89\u88c5\u5b8c\u6210\u4e4b\u540e\uff0c\u518d\u521b\u5efa\u4e00\u4e2a\u7528\u4e8e\u5b58\u50a8drone\u6570\u636e\u7684\u6570\u636e\u5e93\u5b9e\u4f8b\u548c\u7528\u6237<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update\nsudo apt install postgresql\nsu postgres\npsql\ncreate user \u6570\u636e\u5e93\u7528\u6237\u540d with password '\u6570\u636e\u5e93\u5bc6\u7801';\ncreate database \u6570\u636e\u5e93\u5b9e\u4f8b owner \u6570\u636e\u5e93\u7528\u6237\u540d;\nrevoke all on database \u6570\u636e\u5e93\u5b9e\u4f8b from public;<\/code><\/pre>\n\n\n\n<p><strong>3.\u5b89\u88c5pgloader\u5de5\u5177<\/strong><\/p>\n\n\n\n<p>pgloader\u662f\u4e00\u6b3e\u7528\u4e8e\u4ece\u5176\u4ed6\u6570\u636e\u5e93\u5bfc\u6570\u636e\u5230postgresql\u7684\u5de5\u5177\uff0c\u6b64\u5de5\u5177\u5b89\u88c5\u548c\u4f7f\u7528\u6bd4\u8f83\u65b9\u4fbf\uff0c\u4f46\u662f\u6709\u4e00\u4e2a\u7f3a\u9677\uff0c\u5360\u7528\u5185\u5b58\u4f1a\u6bd4\u8f83\u5927\uff0c\u6bd4\u5982\u6211\u8fd9\u91cc\u8981\u5bfc\u5165\u7684sqlite\u6570\u636e\u5e93\u67095\u4e2aG\uff0c\u90a3\u4e48\u8be5\u7a0b\u5e8f\u5728\u8fd0\u884c\u7684\u8fc7\u7a0b\u4e2d\u81f3\u5c11\u8981\u752810\u4e2aG\u7684\u5185\u5b58\uff0c\u5982\u679c\u4e0d\u591f\u7684\u8bdd\uff0c\u4f1a\u5728\u8fd0\u884c\u4e00\u6bb5\u65f6\u95f4\u4e4b\u540e\u88aboom kill \u6389\uff0c\u52a0\u4e0a\u7cfb\u7edf\u672c\u8eab\u8fd0\u884c\u9700\u8981\u4e00\u4e9b\u5185\u5b58\uff0c\u6211\u5efa\u8bae\u5f97\u51c6\u5907\u4e00\u4e2a16G\u5185\u5b58\u7684\u670d\u52a1\u5668<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apt-get install pgloader\n#\u5b89\u88c5\u5b8c\u6210\u540e\u6dfb\u52a0\u4e00\u4e2adb.load\u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a\nload database\n     from sqlite:\/\/\/home\/sfere\/database.sqlite\n     into postgresql:\/\/\u6570\u636e\u5e93\u7528\u6237\u540d:\u6570\u636e\u5e93\u5bc6\u7801@\u6570\u636e\u5e93ip\/\u6570\u636e\u5e93\u5b9e\u4f8b\n\n     with truncate,\n          create tables,\n          create indexes,\n          reset sequences\n;<\/code><\/pre>\n\n\n\n<p><strong>4.\u8f6c\u6362\u524d\u9700\u8981\u91cd\u5efasqlite\u6570\u636e\u5e93&#8221;\u6784\u5efa\u4fe1\u606f\u8868<\/strong>&#8220;<\/p>\n\n\n\n<p class=\"has-black-color has-text-color\">\u5982\u679c\u4e0d\u505a\u8fd9\u4e00\u6b65\uff0c\u4f1a\u62a5\u9519<\/p>\n\n\n\n<p class=\"has-vivid-red-color has-text-color\"><strong>ERROR Database error 42704: type &#8220;number&#8221; does not exist<\/strong>&nbsp;<\/p>\n\n\n\n<p>\u6240\u4ee5\u6211\u4eec\u91cd\u5efabuilds\u8868<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE builds1\n(\n  build_id            bigserial,\n  build_repo_id       bigint,\n  build_trigger       text,\n  build_number        bigint,\n  build_parent        bigint,\n  build_status        text,\n  build_error         text,\n  build_event         text,\n  build_action        text,\n  build_link          text,\n  build_timestamp     bigint,\n  build_title         text,\n  build_message       text,\n  build_before        text,\n  build_after         text,\n  build_ref           text,\n  build_source_repo   text,\n  build_source        text,\n  build_target        text,\n  build_author        text,\n  build_author_name   text,\n  build_author_email  text,\n  build_author_avatar text,\n  build_sender        text,\n  build_deploy        text,\n  build_params        text,\n  build_started       bigint,\n  build_finished      bigint,\n  build_created       bigint,\n  build_updated       bigint,\n  build_version       bigint,\n  build_debug         bool,\n  build_cron          text default '',\n  build_deploy_id     bigint default '0'\n);\n\nINSERT INTO builds1 SELECT * FROM builds;\n\ndrop table builds;\n\nALTER TABLE `builds1` RENAME TO `builds`<\/code><\/pre>\n\n\n\n<p><strong>5.\u5f00\u59cb\u5bfc\u5165\u6570\u636e\u5230postgresql\uff0c\u5bfc\u5165\u5b8c\u6210\u540e\u68c0\u67e5postgresql\u6570\u636e\u5e93\u91cc\u662f\u5426\u6709\u5bf9\u5e94\u7684\u6570\u636e<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pgloader db.load <\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"693\" height=\"385\" src=\"https:\/\/www.yinyubo.com\/wp-content\/uploads\/2023\/07\/image-3.png\" alt=\"\" class=\"wp-image-1245\" srcset=\"https:\/\/www.yinyubo.com\/wp-content\/uploads\/2023\/07\/image-3.png 693w, https:\/\/www.yinyubo.com\/wp-content\/uploads\/2023\/07\/image-3-300x167.png 300w\" sizes=\"auto, (max-width: 693px) 100vw, 693px\" \/><\/figure>\n\n\n\n<p><strong>6.\u5bfc\u5165\u5b8c\u6210\uff0c\u66f4\u65b0drone server\uff0c\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539kubernetes\u8d44\u6e90\u7684\u65b9\u5f0f\uff0c\u6216\u8005\u4fee\u6539helm chart \u7684values.yaml\u7684\u65b9\u5f0f\u6dfb\u52a0\u73af\u5883\u53d8\u91cf<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>DRONE_DATABASE_DRIVER=postgres DRONE_DATABASE_DATASOURCE=postgres:\/\/\u7528\u6237\u540d:\u5bc6\u7801@\u6570\u636e\u5e93IP:5432\/\u6570\u636e\u5e93\u5b9e\u4f8b?sslmode=disable<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u80cc\u666f drone.io\u9ed8\u8ba4\u5b89\u88c5\u7684\u65f6\u5019\u662f\u4f7f\u7528sqlite\u6570\u636e\u5e93\uff0c\u53ef\u4ee5\u7528\u4e8e\u6f14\u793a\u4ea7\u54c1\uff0c\u4f46\u662f\u4e00\u65e6git\u4ed3\u5e93\u6570\u91cf\u8fc7\u591a\uff0cb [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-1241","post","type-post","status-publish","format-standard","hentry","category-influxdb"],"_links":{"self":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/1241","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1241"}],"version-history":[{"count":8,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/1241\/revisions"}],"predecessor-version":[{"id":1253,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/1241\/revisions\/1253"}],"wp:attachment":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1241"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1241"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1241"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}