26 lines
964 B
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- PostgreSQL 初始化脚本:创建应用程序用户
-- 此脚本会在数据库首次初始化时自动执行
-- 创建应用程序用户 iotmanage如果不存在
DO $$
BEGIN
IF NOT EXISTS (SELECT FROM pg_catalog.pg_user WHERE usename = 'iotmanage') THEN
CREATE USER iotmanage WITH PASSWORD 'Iage@Passo#43tMand123!';
RAISE NOTICE '用户 iotmanage 创建成功';
ELSE
RAISE NOTICE '用户 iotmanage 已存在';
END IF;
END
$$;
-- 授予数据库权限
-- 将 jisheiotprodb 数据库的所有权限授予 iotmanage 用户
GRANT ALL PRIVILEGES ON DATABASE jisheiotprodb TO iotmanage;
-- 授予创建数据库权限(如果需要)
ALTER USER iotmanage CREATEDB;
-- 注意schema 权限需要在连接到具体数据库后授予
-- 由于初始化脚本在创建数据库后执行schema 权限会在数据库创建后自动授予
-- 如果需要更细粒度的权限控制,可以创建单独的脚本文件