Android 上 SQLite 数据库的最大大小是多少?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3482635/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is a maximum size of SQLite database on Android?
提问by TN.
I have a SQLite db that size is over 2.6 GiB. (The db contains maps.) This db is used by RMaps app. When move the maps to some parts at maximum zoom, the app suddenly closes. However, there is no force close message, no report button. So, I've got an idea that it is caused by reading blocks that are beyond a certain limit e.g. max(int). Since RMaps is just using simple SQL statements, I think that the problem is not in RMaps but rather in Android SQLite driver.
我有一个大小超过 2.6 GiB 的 SQLite 数据库。(数据库包含地图。)此数据库由 RMaps 应用程序使用。当以最大缩放将地图移动到某些部分时,应用程序突然关闭。但是,没有强制关闭消息,也没有报告按钮。所以,我有一个想法,它是由读取超出某个限制的块引起的,例如 max(int)。由于 RMaps 只是使用简单的 SQL 语句,我认为问题不在于 RMaps,而在于 Android SQLite 驱动程序。
Is there a size limit of SQLite database on Android?
Android 上的 SQLite 数据库有大小限制吗?
(I have Froyo on Nexus One, but I do not think that this is just a problem of Froyo.)
(我在 Nexus One 上有 Froyo,但我不认为这只是 Froyo 的问题。)
Log output:
日志输出:
08-14 10:24:51.689 I/ActivityManager( 81): Starting activity: Intent { act=android.intent.action.SEARCH flg=0x10000000 cmp=com.robert.maps/.MainMapActivity (has extras) }
08-14 10:25:01.879 E/AndroidRuntime(12441): FATAL EXCEPTION: pool-1-thread-2
08-14 10:25:01.879 E/AndroidRuntime(12441): android.database.sqlite.SQLiteDiskIOException: disk I/O error
08-14 10:25:01.879 E/AndroidRuntime(12441): at android.database.sqlite.SQLiteQuery.native_fill_window(Native Method)
08-14 10:25:01.879 E/AndroidRuntime(12441): at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:70)
08-14 10:25:01.879 E/AndroidRuntime(12441): at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:283)
08-14 10:25:01.879 E/AndroidRuntime(12441): at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:264)
08-14 10:25:01.879 E/AndroidRuntime(12441): at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:171)
08-14 10:25:01.879 E/AndroidRuntime(12441): at android.database.AbstractCursor.moveToFirst(AbstractCursor.java:248)
08-14 10:25:01.879 E/AndroidRuntime(12441): at com.robert.maps.utils.CashDatabase.getTile(CashDatabase.java:49)
08-14 10:25:01.879 E/AndroidRuntime(12441): at org.andnav.osm.views.util.OpenStreetMapTileFilesystemProvider.run(OpenStreetMapTileFilesystemProvider.java:501)
08-14 10:25:01.879 E/AndroidRuntime(12441): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
08-14 10:25:01.879 E/AndroidRuntime(12441): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
08-14 10:25:01.879 E/AndroidRuntime(12441): at java.lang.Thread.run(Thread.java:1096)
08-14 10:25:01.889 I/ActivityManager( 81): Process com.robert.maps (pid 12441) has died.
08-14 10:25:01.899 I/WindowManager( 81): WIN DEATH: Window{45131410 com.robert.maps/com.robert.maps.MainMapActivity paused=false}
The SQLite db is stored on SD card, there is enough space.
SQLite db 存储在 SD 卡上,有足够的空间。
回答by Pravin Bhosale
Maximum length of a string or BLOB Default size is 1 GB Max size is 2.147483647
字符串或 BLOB 的最大长度默认大小为 1 GB 最大大小为 2.147483647
Maximum Number Of Columns Default size is 2000 Max size is 32767
最大列数 默认大小为 2000 最大大小为 32767
Maximum Length Of An SQL Statement Default size is 1 MB Max size is 1.073741824
SQL 语句的最大长度默认大小为 1 MB 最大大小为 1.073741824
Maximum Number Of Tables In A Join Default is 64 tables
连接中的最大表数默认为 64 个表
Maximum Number Of Attached Databases Default is 10 Max size is 125
最大附加数据库数默认为 10 最大大小为 125
Maximum Number Of Rows In A Table Max Size is 18446744073.709552765
表中的最大行数最大大小为 18446744073.709552765
Maximum Database Size 140 tb but it will depends on your device disk size.
最大数据库大小 140 tb,但这取决于您的设备磁盘大小。
回答by plaes
I suspect it is ~2 gigabytes (that might be due to 32-bit architecture, although certain programs come with largefile support, allowing more that that). Fortunately android.database.sqlite.SQLiteDatabase
has following API call that returns the maximum size the database may grow to:
我怀疑它是 ~2 GB(这可能是由于 32 位架构,尽管某些程序支持大文件,允许更多)。幸运的是android.database.sqlite.SQLiteDatabase
有以下 API 调用返回数据库可能增长到的最大大小:
long getMaximumSize()
Eventually you might want to look into database sharding ;)
最终你可能想要研究数据库分片;)
回答by Kitson
SQlite has several limits (http://www.sqlite.org/limits.html) that can come into play with any database. Have you tried vaccum;
ing this particular database? It will rebuild the structures. You could have some level of corruption or you have hit one of the other compiled limits that are there to ensure that the DB doesn't become an exploit vector.
SQLite 有几个限制(http://www.sqlite.org/limits.html)可以与任何数据库一起使用。你有没有试过vaccum;
这个特定的数据库?它将重建结构。您可能存在某种程度的损坏,或者您达到了其他编译限制之一,这些限制可确保数据库不会成为漏洞利用向量。
回答by Helzgate
I struggled with getting solid info on this but there are so many variables. This demo Xamarin app allows you to add an example of your own JSON object to an SQLite database repeatedly as fast as you want until you stop it. Allowing you to view the effects both on the size of the database and the performance of the app. It's crude but serves my purposes well and hopefully this can help someone else or you can expand on it. You can find it here.
我努力获得关于这方面的可靠信息,但有很多变数。这个演示 Xamarin 应用程序允许你以你想要的速度重复添加你自己的 JSON 对象的示例到 SQLite 数据库,直到你停止它。允许您查看对数据库大小和应用程序性能的影响。它很粗糙,但很好地满足了我的目的,希望这可以帮助其他人,或者您可以扩展它。你可以在这里找到它。