今天本篇文章带大家了解《Timescale DB 未创建超表》,主要介绍了,希望对大家的知识积累有所帮助,快点收藏起来吧,否则需要时就找不到了!
问题内容
我正在遵循 timescaledb 的教程.. https://docs.timescale.com/timescaledb/latest/how-to-guides/hypertables/create/#create-a-hypertable
但我无法创建超表..我已成功安装 postgres 和 timescale。为什么我不能制作超表?
package main
import (
"context"
"encoding/JSON"
"fmt"
"log"
"os"
"runtime"
"strconv"
"sync"
"GitHub.com/jackc/pgx/v4/pgxpool"
)
func main(){
timeScaleDB()
}
func timeScaleDB(){
psqlInfo := fmt.Sprintf("host=%s port=%d user=%s "+
"passWord=%s dbname=%s sslmode=disable",
host, port, user, password, dbname)
ctx := context.Background()
dbpool, err := pgxpool.Connect(ctx, psqlInfo)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to connect to database: %v\n", err)
os.Exit(1)
}
defer dbpool.Close()
queryCreatetable := `CREATE TABLE sample_table (
time TIMESTAMPTZ NOT NULL,
id INTEGER PRIMARY KEY,
name VARCHAR NOT NULL
);
SELECT create_hypertable('sample_table', 'time');`
//execute statement
_, err = dbpool.Exec(ctx, queryCreatetable)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to create sample_table hypertable: %v\n", err)
os.Exit(1)
}
fmt.Println("Successfully created hypertable sample_table")
}
错误:无法创建sample_table超表:错误:函数create_hypertable(未知,未知)不存在(sqlstate 42883)
正确答案
您能否确认您是否启用了该扩展程序?只需将服务器加入 psql 会话并使用 \dx 命令列出扩展即可:
tsdb=> \dx
list of installed extensions
name | version | schema | description
---------------------+---------+------------+-------------------------------------------------------------------
plpgsql | 1.0 | pg_catalog | pl/pgsql procedural language
timescale_analytics | 0.2 | public | timescale_analytics
timescaledb | 2.2.0 | public | enables Scalable inserts and complex queries for time-series data
...
或者只是尝试提前启用扩展:
CREATE EXTENSION IF NOT EXISTS timescaledb;