Timescale DB not creating hypertable

1.3k views Asked by At

I'm following the tutorial from timescaleDB.. https://docs.timescale.com/timescaledb/latest/how-to-guides/hypertables/create/#create-a-hypertable

but I cant create a hypertable.. I have successfully installed postgres and timescale. Why cant I make a 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")
    }

Error : Unable to create sample_table hypertable: ERROR: function create_hypertable(unknown, unknown) does not exist (SQLSTATE 42883)

1

There are 1 answers

4
jonatasdp On

Can you confirm if you have the extension enabled? Just join the server in a psql session and list the extensions with \dx command:

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
...

Or simply try to enable the extension in advance:

CREATE EXTENSION IF NOT EXISTS timescaledb;