我可以在Android手机中使用postgresql吗?

bik*_*tha 5 postgresql android postgresql-9.3

我正在尝试开发Android应用程序,并且想在应用程序中使用数据库。我知道我可以在Android中使用sqllite,但是可以使用Postgres代替sqllite吗?

我说的是在电话中安装数据库,而不是使用远程数据库服务器。

可能吗?

任何答案表示赞赏。

raz*_*088 7

PostgreSQL现在可以在Andriod上用于Termux

从Play商店安装Termux并运行它。

要安装PostgreSQL:

$ pkg install postgresql
Run Code Online (Sandbox Code Playgroud)

要启动它,首先创建您要在其中存储数据的文件夹,然后再初始化文件夹:

$ mkdir -p $PREFIX/var/lib/postgresql
$ initdb $PREFIX/var/lib/postgresql
Run Code Online (Sandbox Code Playgroud)

要启动服务器:

$ pg_ctl -D $PREFIX/var/lib/postgresql start
Run Code Online (Sandbox Code Playgroud)

要停止服务器:

$ pg_ctl -D $PREFIX/var/lib/postgresql stop
Run Code Online (Sandbox Code Playgroud)

创建一个用户以允许您通过App连接:

$ createuser --superuser --pwprompt yourUserName
Run Code Online (Sandbox Code Playgroud)

创建数据库:

$ createdb mydb
Run Code Online (Sandbox Code Playgroud)

打开你的数据库

$ psql mydb
Run Code Online (Sandbox Code Playgroud)

您现在将看到提示:

mydb=#
Run Code Online (Sandbox Code Playgroud)

PostgreSQL已启动并正在运行。


小智 -2

Android 没有 PostgreSQL 端口。

无法为 Android 编译 PostgreSQL。这确实没有什么意义:PostgreSQL 特别适合大型数据库和多用户访问。此外,您不太可能在 Android 设备上需要 PostGIS 的功能。有多种数据库/空间数据应用程序;或者从可用的工具包中开发自己的工具包。

  • 我需要 postgres,因为我的网络地图应用程序使用 postgres。我不想在移动版本中使用 sqllite,在网络版本中使用 postgres。我需要在移动设备中收集数据,然后在有互联网连接时将数据上传到网络。我的移动应用程序中需要一些空间字段,它必须与 postgres 兼容,而 sqllite 没有。 (6认同)