1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PostgreSQLのマネージドサービス temboを使ってみた

Last updated at Posted at 2024-08-18

temboとは

tembo は Postgres のマネージドサービスです。

類似のサービスには supabase , neon, xata 等 があります。
無料枠という観点では、ベンダーサポートがあるのとストレージサイズが大きいことや拡張性がメリットと言えそうです。一方で可用性は確保されていません。

■ 無料枠比較

機能 supabase neon tembo xata
メモリ 500MB 1GB 1GB ?
ストレージ 1GB 0.5GB 10GB 15GB(+検索エンジン 15GB)
ベンダーサポート なし(有志) なし(有志) あり なし(有志)
拡張機能 ? あり あり なし
ダッシュボード なし ? あり ?

現時点では無料枠はクレカ登録不要で使えます。
現在は次のユースケースに合わせたインスタンスを提供しています。

Stack Replacement for
Standard Amazon RDS
OLTP Amazon RDS
Message Queue Amazon SQS, RabbitMQ, Redis
Mongo Alternative on Postgres MongoDB
Vector DB Pinecone, Weaviate
RAG LangChain
Machine Learning MindsDB
OLAP Snowflake, Bigquery
Data Warehouse Snowflake, Bigquery
Geospatial ESRI, Oracle
Time Series InfluxDB, TimescaleDB

インスタンスの作成

ここからサービスが利用できます。

[Create Instance]ボタンを押下すると、次のように GUI 操作で選択できます

cloud tembo io_orgs_org_2kmfcbwfEEXLG6mMow4nF5kLFBJ_clusters_new_select-type

今回は OLTP を選択します。
機能が制限されますが、無料枠でデプロイします。
2

クライアントの用意

デプロイした postgres サーバーにアクセスするためのクライアントを用意します。
tembo にアクセスするクライアントは SNI をサポートしている必要があります。
psql はデフォルトでサポートしているため、psql を使用します。
ここでは、WSL2 を使用します。

SSL 接続するため、PostgreSQL の公式リポジトリの署名キーをダウンロードします。

sudo apt-get update && sudo apt-get install -y lsb-release
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget -qO- https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo tee /etc/apt/trusted.gpg.d/pgdg.asc &>/dev/null
sudo apt-get update && sudo apt-get install -y postgresql-client

クライアントからサーバに接続

インスタンスが立ち上げ後、Dashboard で postgres サーバ接続文字列を確認します。
3

接続文字列をクリップボードにコピーします
3

これを psql のパラメータに渡します。

psql -U postgres 'postgresql://postgres:YjGD7QtSQNVNywr9@sociably-scrupulous-protozoa.data-1.use1.tembo.io:5432/postgres'
psql (16.3 (Ubuntu 16.3-1.pgdg24.04+1), server 15.7)
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off)
Type "help" for help.

postgres のバージョンは 15.7 のようです。

適当なクエリを実行してみます

postgres=# CREATE OR REPLACE FUNCTION generate_random_string(
  length INTEGER,
  characters TEXT default '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
) RETURNS TEXT AS
$$
DECLARE
  result TEXT := '';
BEGIN
  IF length < 1 then
      RAISE EXCEPTION 'Invalid length';
  END IF;
  FOR __ IN 1..length LOOP
    result := result || substr(characters, floor(random() * length(characters))::int + 1, 1);
  end loop;
  RETURN result;
END;
$$ LANGUAGE plpgsql;
CREATE FUNCTION
postgres=# CREATE TABLE t (
    id int,
    happened_at timestamptz,
    padding text
);
CREATE TABLE
postgres=# INSERT INTO t (
    id,
    happened_at,
    padding
)
SELECT
    n,
    '2023-01-01 UTC'::timestamptz + (interval '1 second' * n),
    generate_random_string(1000)
FROM
    generate_series(1, 1000000) as n;

INSERT 0 1000000

temboのその他機能

  • ダッシュボード
    dashboard

  • 設定変更
    4し

  • 拡張機能
    3

PostgreSQL のマネージドサービスが、無料で使用できるので、ちょっとした実験をするのに便利そうですね。

※まだ若いサービスなので、いくつか問題を見つけましたがこれからに期待です。

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?