Apache Superset:从sqlite迁移到Postgres

问题描述

当我从sqlite迁移到postgres时,无法对新数据库进行任何写操作。 日志显示以下错误

Unique key conflict id= 10,already exist in table ab_user

解决方法

两种可能的情况:

方案A:您是从头开始,并且想要使用Postgres而不是sqlite。

  1. 安装postgres
  2. 将postgres连接字符串添加到superset_config.py文件
  3. 运行superset db upgrade,这将在Postgres上创建所有表
  4. 运行superset init
  5. 启动超集

场景B::您已经填充了sqliteDB,并希望将其迁移到Postgres。

  1. 安装postgres
  2. 将postgres连接字符串添加到superset_config.py文件
  3. 将所有表从sqlite复制到postgres,可以通过多种方法进行。我的首选方法是使用红宝石
  4. 复制数据后,运行superset db upgradesuperset init
  5. 完成此操作后,您将需要更新表information_schema.sequences上Postgres上的键序列,否则将遇到唯一的键冲突错误。
  6. 启动超集

在两种情况下,运行superset db upgrade后,您都应该在下面看到消息,这意味着您已经正确配置了superset_config.py。

INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.

通过设置环境变量,确保超集正在查看配置文件:

export PYTHONPATH=/home/local_settings/:$PYTHONPATH
OR
export SUPERSET_CONFIG_PATH=/home/local_settings/