ubuntu20.04 下安装 postgresql13

参考: https://www.postgresql.org/download/linux/ubuntu/

sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

# Import the repository signing key:
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

# Update the package lists:
sudo apt-get update

# Install the latest version of PostgreSQL.
# If you want a specific version, use 'postgresql-12' or similar instead of 'postgresql':
sudo apt-get -y install postgresql-13 php-pgsql

安装完成后,默认会:

(1)创建名为"postgres"的Linux用户

(2)创建名为"postgres"、不带密码的默认数据库账号作为数据库管理员

(3)创建名为"postgres"的表

修改数据库密码:

Step1: 切换用户为postgres

  sudo su postgres

Step2: 用postgres连接postgreSQL

  psql -U postgres

Step3: 修改postgres密码

  alter user postgres with password 'new password';

现在postgres用户就拥有了新密码

windows10下安装 postgresql13

安装版下载: https://www.enterprisedb.com/downloads/postgres-postgresql-downloads

安装目录: C:\PostgreSQL\13 ,数据目录: C:\PostgreSQL\13\data ,安装信息:

Installation Directory: C:\PostgreSQL\13
Server Installation Directory: C:\PostgreSQL\13
Data Directory: C:\PostgreSQL\13\data
Database Port: 5432
Database Superuser: postgres
Operating System Account: NT AUTHORITY\NetworkService
Database Service: postgresql-x64-13
Command Line Tools Installation Directory: C:\PostgreSQL\13
pgAdmin4 Installation Directory: C:\PostgreSQL\13\pgAdmin 4
Stack Builder Installation Directory: C:\PostgreSQL\13

安装 php,nginx

参考 https://yinhe.co/archives/20201022_typecho.html 安装

安装typecho

一定要从github下载master分支代码安装, typecho的稳定版本对postgresql支持有问题,很多bug是在master版本中修复的。

handsome主题500错误

错误提示:Database Query Error

主题官方文档帮助信息:

安装完主题后,页面中间部分空白/安装后首页报错,500错误
依次检查主题文件夹名称是否为handsome,插件文件夹名称为Handsome(首字母大写)
是否已经安装并且启用主题必要的插件Handsome
php版本5.5+,必须安装mbstring和openssl扩展,否则无法使用(正确检查方式是在你的服务器新建一个test.php,然后复制粘贴该代码<?php phpinfo(); ?>,最后在浏览器访问该文件可以查看服务器的php信息)
主题目录下面的lisence文件给777权限,包括递归子文件夹和子文件,也可以尝试给644或者755权限。因为有的服务器上传文件之后,默认给的权限php都没办法执行的
最后确保自己上传的文件没有缺失,比如handsome文件夹下有fucntions.php,Handsome文件夹下有Plugin.php 则是最起码的
初次使用主题必须保证博客有一篇文章,如果一篇文章都没有的话会导致向数据库中添加view(浏览次数字段)失败
PostgreSql数据库安装links插件时,需要手动新建typechos_links表。(会在下一个版本修复)

解决方式:

1.供创建和修改表参考的: sqlite数据库中contents,links 表创建信息

CREATE TABLE typecho_contents ( "cid" INTEGER NOT NULL PRIMARY KEY,
"title" varchar(200) default NULL ,
"slug" varchar(200) default NULL ,
"created" int(10) default '0' ,
"modified" int(10) default '0' ,
"text" text ,
"order" int(10) default '0' ,
"authorId" int(10) default '0' ,
"template" varchar(32) default NULL ,
"type" varchar(16) default 'post' ,
"status" varchar(16) default 'publish' ,
"password" varchar(32) default NULL ,
"commentsNum" int(10) default '0' ,
"allowComment" char(1) default '0' ,
"allowPing" char(1) default '0' ,
"allowFeed" char(1) default '0' ,
"parent" int(10) default '0' , `views` INT(10) DEFAULT 0, `agree` INT(10) NOT NULL DEFAULT 0)

CREATE TABLE `typecho_links` (
  `lid` INTEGER NOT NULL PRIMARY KEY,
  `name` varchar(200) default NULL,
  `url` varchar(200) default NULL,
  `sort` varchar(200) default NULL,
  `image` varchar(200) default NULL,
  `description` varchar(200) default NULL,
  `user` varchar(200) default NULL,
  `order` int(10) default '0'
)

2.供创建和修改表参考的:PostgreSQL中contents表创建信息

-- Table: public.typecho_contents

-- DROP TABLE public.typecho_contents;

CREATE TABLE public.typecho_contents
(
    cid integer NOT NULL DEFAULT nextval('typecho_contents_seq'::regclass),
    title character varying(150) COLLATE pg_catalog."default" DEFAULT NULL::character varying,
    slug character varying(150) COLLATE pg_catalog."default" DEFAULT NULL::character varying,
    created integer DEFAULT 0,
    modified integer DEFAULT 0,
    text text COLLATE pg_catalog."default",
    "order" integer DEFAULT 0,
    "authorId" integer DEFAULT 0,
    template character varying(32) COLLATE pg_catalog."default" DEFAULT NULL::character varying,
    type character varying(16) COLLATE pg_catalog."default" DEFAULT 'post'::character varying,
    status character varying(16) COLLATE pg_catalog."default" DEFAULT 'publish'::character varying,
    password character varying(32) COLLATE pg_catalog."default" DEFAULT NULL::character varying,
    "commentsNum" integer DEFAULT 0,
    "allowComment" character(1) COLLATE pg_catalog."default" DEFAULT '0'::bpchar,
    "allowPing" character(1) COLLATE pg_catalog."default" DEFAULT '0'::bpchar,
    "allowFeed" character(1) COLLATE pg_catalog."default" DEFAULT '0'::bpchar,
    parent integer DEFAULT 0,
    CONSTRAINT typecho_contents_pkey PRIMARY KEY (cid),
    CONSTRAINT typecho_contents_slug_key UNIQUE (slug)
)

TABLESPACE pg_default;

ALTER TABLE public.typecho_contents
    OWNER to postgres;
-- Index: typecho_contents_created

-- DROP INDEX public.typecho_contents_created;

CREATE INDEX typecho_contents_created
    ON public.typecho_contents USING btree
    (created ASC NULLS LAST)
    TABLESPACE pg_default;

3.修改pg中的contents表

ALTER TABLE typecho_contents ADD COLUMN IF NOT EXISTS views integer DEFAULT 0;

4.创建表 typecho_links

CREATE SEQUENCE typecho_links_seq
    INCREMENT 1
    START 1
    MINVALUE 1
    MAXVALUE 9223372036854775807
    CACHE 1;

CREATE TABLE typecho_links (
  lid integer NOT NULL DEFAULT nextval('typecho_links_seq'::regclass),
  name character varying(150) COLLATE pg_catalog."default" DEFAULT NULL::character varying,  
  url character varying(150) COLLATE pg_catalog."default" DEFAULT NULL::character varying,
  sort character varying(150) COLLATE pg_catalog."default" DEFAULT NULL::character varying,
  image character varying(150) COLLATE pg_catalog."default" DEFAULT NULL::character varying,
  description character varying(150) COLLATE pg_catalog."default" DEFAULT NULL::character varying,
  "user" character varying(150) COLLATE pg_catalog."default" DEFAULT NULL::character varying,
  "order"  integer DEFAULT 0
);

5.handsome主题下加载首页继续报错

错误信息类似:

SQLSTATE[22003]: Numeric value out of range: 7 错误:  值 "-8639999998396321618" 超出类型 integer 的范围
LINE 1: ...ECT *  FROM typecho_contents WHERE  ("created" >= '-86399999...
                                                             ^
Typecho_Db_Query_Exception: SQLSTATE[22003]: Numeric value out of range: 7 错误:  值 "-8639999998396321618" 超出类型 integer 的范围
LINE 1: ...ECT *  FROM typecho_contents WHERE  ("created" >= '-86399999...
                                                             ^ in D:\博客\typecho_local\typecho\var\Typecho\Db\Adapter\Pdo.php:105
Stack trace:
#0 D:\博客\typecho_local\typecho\var\Typecho\Db\Adapter\Pdo\Pgsql.php(111): Typecho_Db_Adapter_Pdo->query('SELECT *  FROM ...', Object(PDO), 1, 'SELECT', 'typecho_content...')
#1 D:\博客\typecho_local\typecho\var\Typecho\Db.php(367): Typecho_Db_Adapter_Pdo_Pgsql->query('SELECT *  FROM ...', Object(PDO), 1, 'SELECT', 'typecho_content...')
#2 D:\博客\typecho_local\typecho\var\Typecho\Db.php(398): Typecho_Db->query(Object(Typecho_Db_Query), 1)
#3 D:\博客\typecho_local\typecho\usr\themes\handsome\libs\Content.php(3068): Typecho_Db->fetchAll(Object(Typecho_Db_Query))
#4 D:\博客\typecho_local\typecho\usr\themes\handsome\component\sidebar.php(24): Content::returnHotPosts(Object(Widget_Archive))
#5 D:\博客\typecho_local\typecho\var\Widget\Archive.php(1952): require('D:\\\xE5\x8D\x9A\xE5\xAE\xA2\\typec...')
#6 D:\博客\typecho_local\typecho\usr\themes\handsome\index.php(84): Widget_Archive->need('component/sideb...')
#7 D:\博客\typecho_local\typecho\var\Widget\Archive.php(2037): require_once('D:\\\xE5\x8D\x9A\xE5\xAE\xA2\\typec...')
#8 D:\博客\typecho_local\typecho\var\Typecho\Router.php(138): Widget_Archive->render()
#9 D:\博客\typecho_local\typecho\index.php(23): Typecho_Router::dispatch()
#10 {main}

handsome 7.3.1 主题bug, 修改 typecho\usr\themes\handsome\libs\Content.php 3043 行前后

public static function returnHotPosts($hot)
    {
        $options = mget();
        //$days = 99999999999999;
        // 365*40 = 14600
        $days = 14600;

最后修改:2020 年 10 月 25 日 11 : 20 AM
如果觉得我的文章对你有用,请随意赞赏