[{"data":1,"prerenderedAt":354},["ShallowReactive",2],{"page-\u002Fself-hosting\u002Fdatabase":3},{"id":4,"title":5,"body":6,"description":347,"extension":348,"meta":349,"navigation":99,"path":350,"seo":351,"stem":352,"__hash__":353},"content\u002F4.self-hosting\u002F1.database.md","Database",{"type":7,"value":8,"toc":342},"minimark",[9,14,40,44,191,195,203,314,328,331,338],[10,11,13],"h2",{"id":12},"what-you-need","What you need",[15,16,17,21,24],"ul",{},[18,19,20],"li",{},"Postgres 18 with PostGIS.",[18,22,23],{},"The TIN extension: PlanetScale TIN in production, or the Tantivy-backed Lead fork for local development.",[18,25,26,27,31,32,39],{},"The ",[28,29,30],"code",{},"geocoding"," table from geolith's pg-copy output. See the ",[33,34,38],"a",{"href":35,"rel":36},"https:\u002F\u002Fdocs.geolith.app\u002Fguides\u002Fgeocoding-output",[37],"nofollow","geolith geocoding guide",".",[10,41,43],{"id":42},"indexes","Indexes",[45,46,51],"pre",{"className":47,"code":48,"language":49,"meta":50,"style":50},"language-sql shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","CREATE EXTENSION IF NOT EXISTS postgis;\nCREATE EXTENSION IF NOT EXISTS tin;\n\n-- Lets the TIN top-k scan bound the importance term.\nCREATE INDEX ON geocoding (importance);\n\n-- Focus boxes and reverse geocoding.\nCREATE INDEX geocoding_location_idx ON geocoding USING gist (ST_MakePoint(lon, lat));\n\n-- Full-text search.\nCREATE INDEX geocoding_search_text_idx ON geocoding USING tin (search_text);\nANALYZE geocoding;\n","sql","",[28,52,53,78,94,101,108,123,128,134,155,160,166,185],{"__ignoreMap":50},[54,55,58,62,66,69,72,75],"span",{"class":56,"line":57},"line",1,[54,59,61],{"class":60},"sbssI","CREATE",[54,63,65],{"class":64},"sTEyZ"," EXTENSION ",[54,67,68],{"class":60},"IF",[54,70,71],{"class":60}," NOT",[54,73,74],{"class":60}," EXISTS",[54,76,77],{"class":64}," postgis;\n",[54,79,81,83,85,87,89,91],{"class":56,"line":80},2,[54,82,61],{"class":60},[54,84,65],{"class":64},[54,86,68],{"class":60},[54,88,71],{"class":60},[54,90,74],{"class":60},[54,92,93],{"class":64}," tin;\n",[54,95,97],{"class":56,"line":96},3,[54,98,100],{"emptyLinePlaceholder":99},true,"\n",[54,102,104],{"class":56,"line":103},4,[54,105,107],{"class":106},"sHwdD","-- Lets the TIN top-k scan bound the importance term.\n",[54,109,111,113,116,120],{"class":56,"line":110},5,[54,112,61],{"class":60},[54,114,115],{"class":60}," INDEX",[54,117,119],{"class":118},"s2Zo4"," ON",[54,121,122],{"class":64}," geocoding (importance);\n",[54,124,126],{"class":56,"line":125},6,[54,127,100],{"emptyLinePlaceholder":99},[54,129,131],{"class":56,"line":130},7,[54,132,133],{"class":106},"-- Focus boxes and reverse geocoding.\n",[54,135,137,139,141,144,146,149,152],{"class":56,"line":136},8,[54,138,61],{"class":60},[54,140,115],{"class":60},[54,142,143],{"class":118}," geocoding_location_idx",[54,145,119],{"class":60},[54,147,148],{"class":64}," geocoding ",[54,150,151],{"class":60},"USING",[54,153,154],{"class":64}," gist (ST_MakePoint(lon, lat));\n",[54,156,158],{"class":56,"line":157},9,[54,159,100],{"emptyLinePlaceholder":99},[54,161,163],{"class":56,"line":162},10,[54,164,165],{"class":106},"-- Full-text search.\n",[54,167,169,171,173,176,178,180,182],{"class":56,"line":168},11,[54,170,61],{"class":60},[54,172,115],{"class":60},[54,174,175],{"class":118}," geocoding_search_text_idx",[54,177,119],{"class":60},[54,179,148],{"class":64},[54,181,151],{"class":60},[54,183,184],{"class":64}," tin (search_text);\n",[54,186,188],{"class":56,"line":187},12,[54,189,190],{"class":64},"ANALYZE geocoding;\n",[10,192,194],{"id":193},"faster-index-with-the-lead-fork","Faster index with the Lead fork",[196,197,198,199,202],"p",{},"The local Lead fork can copy columns into the text index and store word prefixes. Set these before ",[28,200,201],{},"CREATE INDEX",":",[45,204,206],{"className":47,"code":205,"language":49,"meta":50,"style":50},"SET maintenance_work_mem = '2GB';\nSET tin.build_memory_mb = 8192;\nSET tin.rank_columns = 'importance,lon,lat';\nSET tin.index_prefixes = '2,5';\nCREATE INDEX geocoding_search_text_idx ON geocoding USING tin (search_text);\nRESET tin.rank_columns;\nRESET tin.index_prefixes;\n",[28,207,208,233,247,265,283,299,307],{"__ignoreMap":50},[54,209,210,213,216,220,223,227,230],{"class":56,"line":57},[54,211,212],{"class":60},"SET",[54,214,215],{"class":64}," maintenance_work_mem ",[54,217,219],{"class":218},"sMK4o","=",[54,221,222],{"class":218}," '",[54,224,226],{"class":225},"sfazB","2GB",[54,228,229],{"class":218},"'",[54,231,232],{"class":64},";\n",[54,234,235,237,240,242,245],{"class":56,"line":80},[54,236,212],{"class":60},[54,238,239],{"class":64}," tin.build_memory_mb ",[54,241,219],{"class":218},[54,243,244],{"class":60}," 8192",[54,246,232],{"class":64},[54,248,249,251,254,256,258,261,263],{"class":56,"line":96},[54,250,212],{"class":60},[54,252,253],{"class":64}," tin.rank_columns ",[54,255,219],{"class":218},[54,257,222],{"class":218},[54,259,260],{"class":225},"importance,lon,lat",[54,262,229],{"class":218},[54,264,232],{"class":64},[54,266,267,269,272,274,276,279,281],{"class":56,"line":103},[54,268,212],{"class":60},[54,270,271],{"class":64}," tin.index_prefixes ",[54,273,219],{"class":218},[54,275,222],{"class":218},[54,277,278],{"class":225},"2,5",[54,280,229],{"class":218},[54,282,232],{"class":64},[54,284,285,287,289,291,293,295,297],{"class":56,"line":110},[54,286,61],{"class":60},[54,288,115],{"class":60},[54,290,175],{"class":118},[54,292,119],{"class":60},[54,294,148],{"class":64},[54,296,151],{"class":60},[54,298,184],{"class":64},[54,300,301,304],{"class":56,"line":125},[54,302,303],{"class":60},"RESET",[54,305,306],{"class":64}," tin.rank_columns;\n",[54,308,309,311],{"class":56,"line":130},[54,310,303],{"class":60},[54,312,313],{"class":64}," tin.index_prefixes;\n",[15,315,316,322],{},[18,317,318,321],{},[28,319,320],{},"tin.rank_columns"," ranks by importance inside the index and skips rows outside a focus box.",[18,323,324,327],{},[28,325,326],{},"tin.index_prefixes = '2,5'"," stores every 2–5 character word prefix, so autocomplete reads one posting list.",[196,329,330],{},"The SQL that geolith search sends is the same with or without these settings.",[332,333,335],"alert",{"type":334},"warning",[196,336,337],{},"The prefix index is larger. On the 555.6 million row planet table the index is 32 GB, and the build needs about twice that in free disk space while it merges.",[339,340,341],"style",{},"html pre.shiki code .sbssI, html code.shiki .sbssI{--shiki-light:#F76D47;--shiki-default:#F78C6C;--shiki-dark:#F78C6C}html pre.shiki code .sTEyZ, html code.shiki .sTEyZ{--shiki-light:#90A4AE;--shiki-default:#EEFFFF;--shiki-dark:#BABED8}html pre.shiki code .sHwdD, html code.shiki .sHwdD{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#546E7A;--shiki-default-font-style:italic;--shiki-dark:#676E95;--shiki-dark-font-style:italic}html pre.shiki code .s2Zo4, html code.shiki .s2Zo4{--shiki-light:#6182B8;--shiki-default:#82AAFF;--shiki-dark:#82AAFF}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sMK4o, html code.shiki .sMK4o{--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF}html pre.shiki code .sfazB, html code.shiki .sfazB{--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D}",{"title":50,"searchDepth":80,"depth":80,"links":343},[344,345,346],{"id":12,"depth":80,"text":13},{"id":42,"depth":80,"text":43},{"id":193,"depth":80,"text":194},"Build the geocoding table and the indexes geolith search needs.","md",{},"\u002Fself-hosting\u002Fdatabase",{"title":5,"description":347},"4.self-hosting\u002F1.database","_4VstoCnG1f5c0l3UlNeY96cndxGuHMNsU1qtgDPxRc",1791345919739]