用于在数据库

时间:2015-06-30 12:54:47

标签: postgresql schema postgis large-data

我需要存储大量的位置坐标及其时间戳。以下是当前表架构的外观:

User_ID, Location_Coordinate, Timestamp

在连续跟踪每个用户的情况下,将为每个用户生成许多位置坐标。有多个用户。什么是有效存储此类数据的正确方法?

我需要为每个用户检索过去24小时的数据。

1 个答案:

答案 0 :(得分:1)

The easiest way is to store it all in a single table with a PostGIS geometry column for the location. What is "efficient" depends entirely on your application. There are a few things to consider:

  • If you want to store each and every location of every user, use a regular table. Whether or not you should use indexes depends on the number of inserts (new locations being entered) and how you retrieve the data. Very frequent inserts means that the indexes have to be updated frequently; that is a performance penalty.
  • If you get more locations than you need for your application (e.g. automatic pushing of the current location from a (GPS) device), then you might want to consider using an unlogged table without indexes (which is therefore very fast to insert) and then regularly poll that table for new records, process them (i.e. reduce number of locations to store only the relevant ones), and store the processed data permanently in another table with the appropriate indexes. There are many processing function in PostGIS that you could use for this purpose. Keep that unlogged table small (poll regularly and delete processed data) and you won't miss the indexes. You would then query this latter table for the past 24 hours and use the unlogged table only for newly received locations.

Otherwise, there is not much advice that can be given with the limited information that you supply. Edit your question with more details and you will get a more detailed answer.