gpt4 book ai didi

go - 时间刻度数据库不创建超表

转载 作者:行者123 更新时间:2023-12-02 02:13:18 24 4
gpt4 key购买 nike

我正在学习 timescaleDB 的教程...... https://docs.timescale.com/timescaledb/latest/how-to-guides/hypertables/create/#create-a-hypertable

但我无法创建超表。我已经成功安装了 postgres 和 timescale。为什么我不能制作 hypertable?

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(unknown, unknown) 不存在 (SQLSTATE 42883)

最佳答案

您能否确认您是否启用了扩展程序?只需在 psql session 中加入服务器并使用 \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;

关于go - 时间刻度数据库不创建超表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67469221/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com