在幸狐RV1106開發板上用gcc14.2本地編譯安裝postgresql 17.5資料庫
編譯環境:
RV1106G3
Linux luckfox-rv1106 5.10.160 #3 Fri Jun 27 14:16:20 AWST 2025 armv7l GNU/Linux
BusyBox v1.36.1
gcc version 14.2.0 (GCC)
GNU ld (GNU Binutils) 2.44
GNU Make 4.4
ncurses 6.5.20240427(libncursesw.so.6.5)
OpenSSL 1.1.1w 11 Sep 2023
瑞芯微RV1106從SD卡啟動自己的busybox1.36.1根文件系統:https://zh.purasbar.com/post.php?t=32786
在fedora42上用arm-gnu-toolchain-14.2交叉編譯器編譯gcc14.2、gdb14.2和make4.4:https://zh.purasbar.com/post.php?t=32816
在瑞芯微RV1106板子上用gcc14.2本地編譯安裝apache2.4.63,開啟http2和tls1.3,並且https支持XP系統的IE6-8瀏覽器:https://zh.purasbar.com/post.php?t=32825
工作目錄:
mkdir ~/software/postgresql
cd ~/software/postgresql
【編譯安裝icu4c-77_1】
[方法1: 在板子上本地編譯]
wget https://github.com/unicode-org/icu/releases/download/release-77-1/icu4c-77_1-src.tgz --no-check-certificate
tar xf icu4c-77_1-src.tgz
cd icu/source
./configure --with-data-packaging=files
make
批量創建文件夾:
mkdir -p $(find data/out/build -type d | sed "s/data\/out\/build/\/usr\/local\/share\/icu\/77.1/")
注意文件夾名字中的版本號。如果不知道的話,可以先執行make install看看報錯信息。
make install
cd ../..
[方法2: 在電腦上交叉編譯]
export PATH=$PATH:/home/oct1158/Downloads/arm-gnu-toolchain-14.2.rel1-x86_64-arm-none-linux-gnueabihf/bin
wget https://github.com/unicode-org/icu/releases/download/release-77-1/icu4c-77_1-src.tgz
tar xf icu4c-77_1-src.tgz
cd icu
mkdir _build
cd _build
../source/configure
make
mkdir ../_build2
cd ../_build2
../source/configure --host=arm-none-linux-gnueabihf --with-cross-build=$(pwd)/../_build --with-data-packaging=files
make
修改data/Makefile文件:第172-181行,把每一行的$(ICUPKGDATA_DIR)都改成$(DESTDIR)$(ICUPKGDATA_DIR)。
批量創建文件夾:
mkdir -p $(find data/out/build -type d | sed "s/data\/out\/build/_install\/usr\/local\/share\/icu\/77.1/")
注意文件夾名字中的版本號。如果不知道的話,可以先執行make install DESTDIR=$(pwd)/_install看看報錯信息。
make install DESTDIR=$(pwd)/_install
cd _install
sudo chown -R root:root usr
tar czf icu4c-77_1-binary.tar.gz usr
mv icu4c-77_1-binary.tar.gz /var/www/html/oct1158
[測試icu庫是否能正常工作(非常重要)]
先運行一下ldconfig。
執行:/usr/local/bin/icuinfo
提示:ICU Initialization returned: U_FILE_ACCESS_ERROR
執行:ICU_DATA=/usr/local/share/icu/77.1 /usr/local/bin/icuinfo
提示:ICU Initialization returned: U_ZERO_ERROR
看到U_ZERO_ERROR就說明正常了。
修改/etc/profile文件:添加export ICU_DATA=/usr/local/share/icu/77.1。
改完後用exit命令退出命令行,再按回車鍵重新進入命令行。
【編譯安裝bison-3.8.2】
wget https://ftp.gnu.org/gnu/bison/bison-3.8.2.tar.gz --no-check-certificate
tar xf bison-3.8.2.tar.gz
cd bison-3.8.2
./configure
make
make install
cd ..
【編譯安裝flex-2.6.4】
wget https://github.com/westes/flex/releases/download/v2.6.4/flex-2.6.4.tar.gz --no-check-certificate
tar xf flex-2.6.4.tar.gz
cd flex-2.6.4
./configure
make
make install
cd ..
【編譯安裝readline-8.2.13】
wget https://ftp.gnu.org/gnu/readline/readline-8.2.13.tar.gz --no-check-certificate
tar xf readline-8.2.13.tar.gz
cd readline-8.2.13
./configure
make
make install
ldconfig
cd ..
【編譯安裝postgresql-17.5】
wget https://ftp.postgresql.org/pub/source/v17.5/postgresql-17.5.tar.gz --no-check-certificate
tar xf postgresql-17.5.tar.gz
cd postgresql-17.5
./configure LDFLAGS="-lncursesw"
(如果報Could not execute a simple test program.的錯誤,說明之前忘記了執行ldconfig。請檢查gcc helloworld.c -o helloworld -lreadline -lncursesw編譯出來的程序是否能成功執行,helloworld.c裡面是空白main函數。)
make
make install
ldconfig
cd ..
【使用postgresql-17.5資料庫】
給/dev/urandom添加權限:chmod o+rw /dev/urandom(不添加權限的話會報running bootstrap script ... 2025-06-30 08:31:57.060 UTC [415] PANIC: could not generate secret authorization token的錯誤)
給/dev/null添加權限:chmod o+rw /dev/null
添加postgres用戶和組:adduser postgres
登錄postgres用戶:su postgres
初始化資料庫:/usr/local/pgsql/bin/initdb -D /home/postgres/data
[root@luckfox-rv1106 /]# ls /home/postgres/
[root@luckfox-rv1106 /]# su postgres
[postgres@luckfox-rv1106 /]$ /usr/local/pgsql/bin/initdb -D /home/postgres/data
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "C".
The default database encoding has accordingly been set to "SQL_ASCII".
The default text search configuration will be set to "english".
Data page checksums are disabled.
creating directory /home/postgres/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... sysv
selecting default "max_connections" ... 100
selecting default "shared_buffers" ... 128MB
selecting default time zone ... UTC
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... 2025-06-30 11:32:18.303 UTC [368] WARNING: no usable system locales were found
ok
syncing data to disk ... ok
initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
/usr/local/pgsql/bin/pg_ctl -D /home/postgres/data -l logfile start
[postgres@luckfox-rv1106 /]$ ls ~
data
[postgres@luckfox-rv1106 /]$
如果報下面的錯誤:
performing post-bootstrap initialization ... 2025-06-30 11:28:10.430 UTC [341] FATAL: could not open collator for locale "und": U_FILE_ACCESS_ERROR
2025-06-30 11:28:10.430 UTC [341] STATEMENT: UPDATE pg_collation SET collversion = pg_collation_actual_version(oid) WHERE collname = 'unicode';
要麼是編譯icu庫的時候沒帶--with-data-packaging=files選項,要麼是沒有在/etc/profile文件中添加export ICU_DATA=/usr/local/share/icu/77.1環境變量,要麼是改了/etc/profile文件但沒用exit命令退出命令行再按回車鍵重新進入命令行。
(postgres用戶)啟動資料庫伺服器:/usr/local/pgsql/bin/pg_ctl -D ~/data -l ~/logfile start
(postgres用戶)創建mydb資料庫:/usr/local/pgsql/bin/createdb mydb
(postgres用戶)進入資料庫:/usr/local/pgsql/bin/psql
查看資料庫列表:\l
選擇資料庫:\c mydb
創建表:create table test (id serial, title character varying(500), time timestamp default now(), primary key(id));
查看表結構:\d test
插入記錄:
insert into test (title) values ('安裝黑翼貓擴展內核能使win2000 sp4的ie6瀏覽器支持sha256簽名的https證書'),
('安裝微軟官方的KB968730補丁能使64位winxp sp2的ie6-8瀏覽器支持sha256簽名的https證書'),
('32位winxp sp3的ie6-8瀏覽器原生支持sha256簽名的https證書'),
('只要採用sha1簽名的https證書,2025年的apache2.4.63的https不僅支持xp系統的ie6-8瀏覽器,還支持原版win2000 sp4系統的ie5-6瀏覽器'),
('xp系統安裝one core api 4.0.1補丁後,可以安裝和運行vscode1.70.2,VSCodeUserSetup安裝包文件的屬性裡面的兼容性下拉框要記得選擇win7sp1');
查看表數據:select * from test;
退出資料庫:\q
(postgres用戶)關閉資料庫伺服器:/usr/local/pgsql/bin/pg_ctl -D ~/data stop
執行/usr/local/pgsql/bin/psql時如果報錯:
psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
解決辦法:在root用戶下chmod o+rw /dev/urandom。
建議將chmod o+rw /dev/urandom和chmod o+rw /dev/null添加到開機腳本/etc/init.d/rcS裡面。