---
title: "postgres 创建数据库"
author: "liubl2011"
date: "2012-12-20T15:13:09Z"
tags: []
categories: ["数据库"]
slug: "postgres"
draft: false
lastmod: "2012-12-20T15:13:09Z"
id: 1751094
url: "https://liubl2011.iteye.com/blog/1751094"
---

发现没有ak的手册自己建库是比较头痛的事。所以俺把sky创建库的过程笔记发到这里，以便不时之需。
首先切换用户
su - postgres
创建角色
 create role dbuser nosuperuser login encrypted password 'dbpwd';
注:dbuser是你要建的角色名，dbpwd为你用户的密码
创建表空间
 create tablespace tbs_dbname owner psiserver location '/var/pgdata/tbs/tbs_db';
注:tbs_dbname 是你要建的空间名。
创建数据库
 create database dbname with owner dbuser template template0 encoding 'UTF8' tablespace tbs_dbname ;
进入数据库
\c dbuser dbname
创建schema
create schema dbschema authorization dbname;

打完收工

小宝制造。